본문 바로가기

IT To do and To was

22년 1월 6일_젤네일 이상한가..?ㅜㅜ

728x90
반응형

목요일[공허하네]

 

1. 수업을 시작한지 일주일이 지났다.

2. 언니가 심란하댄당..(+내 피부는 언제 좋아지는 거지..)

3. 수업 all clear

 

1. 8day

데이터 라이브러리 종류

numpy 배열_백터

pandos

seaborn -시각화

matplatlib-시각화

 

RDB_정형화 /  noSQL_비정형 / file_반정형

 

https의 s는 암호화를 뜻하며 200, 300,4xx등은 상태 코드, 서버에서 클라이언트로 보내는 타입은 html임

 

요청메소드 중 post와 get

post = 요청의 바디를 따라감

get = 요청의 주소를 따라감

 

동기식, 비동기식 _xml, json으로 넘어오며 위키피디아에 보면 상태코드가 잘 나와있다고 함

https://www.wikipedia.org/

 

Wikipedia

If Wikipedia has given you $2.75 worth of knowledge this year, take a minute to donate. Donate now

www.wikipedia.org

 

쿼리 스트링에 parameter 샘플코드 : 키 --딕셔너리 처럼 생김

 

butiful에서 json, lods, 나 xml.pnsol이렇게 기재

 

import numpy as np #numpy 의 축약 = np

#array는 크기가 고정 , 인덱스로 접근. 0부터 2d (0,0)- (0,1) [[1,2,3],[4,5,6]]2차원 0행, 1행
# arr = np.array([1,2,3,4,5])
# arr = np.array([[1,2,3],[4,5]])
# arr = np.array([[[1,2,3],
#                 [4,5]],
#                 [[1,2,3],
#                 [4,5,6]]])
arr = np.array([
                [[1, 2, 3], [4, 5, 6], [7, 8, 9]],
                [[1, 2, 3], [13, 14, 15], [16, 17, 18]]
                ])

print(arr)
print(arr.shape) #배열의 형태
print(arr.dtype) #dtype
print(arr.ndim) #차원수
print(arr.size) #요소의 개수
print(arr.itemsize) #요소 데이터 타입의 크기(byte단위)
print(arr.data) #실제 데이터
[[[ 1  2  3]
  [ 4  5  6]
  [ 7  8  9]]

 [[ 1  2  3]
  [13 14 15]
  [16 17 18]]]
(2, 3, 3)
int32
3
18
4
<memory at 0x00000294A89309A0>
In [33]:
# zeros, ones, full 
ry = np.zeros((3, 4)) #배열을 생성하고, 모든 요소를 0으로 초기화
print(ry)

ay = np.ones((2,3,4),dtype=np.int16) #2개의 배열, 3행 4열을 ones로 1을 넣고 int로 dtype을 설정
print(ay)

rry = np.full((2,2),7) # np.full(shape, fill_value, dtype=None, order='C'), 지정된 shape의 배열을 생성하고, 모든 요소를 지정한 "fill_value"로 초기화
print(rry)
[[0. 0. 0. 0.]
 [0. 0. 0. 0.]
 [0. 0. 0. 0.]]
[[[1 1 1 1]
  [1 1 1 1]
  [1 1 1 1]]

 [[1 1 1 1]
  [1 1 1 1]
  [1 1 1 1]]]
[[7 7]
 [7 7]]
In [35]:
# start부터 stop의 범위에서 num개를 균일한 간격으로 데이터를 생성하고 배열을 만드는 함수
oy = np.linspace(0, 1, 5) 
print(oy)
[0.   0.25 0.5  0.75 1.  ]
In [40]:
#-1 맨 끝에꺼
arr = np.array([[1,2,3],[4,5,6]])

for x in arr :  #열 추출
    for f in x : #안에 있는__, 추출
        print(f)
        
arr = np.array([[[1,2,3],[4,5,6]],[[7,8,9],[10,11,12]]]) #3차원

for z in arr :
    for o in z :
        for v in o :
            print(v)
1
2
3
4
5
6
1
2
3
4
5
6
7
8
9
10
11
12
In [41]:
arr = np.array([[0, 1, 2, 3], [4, 5, 6, 7]])

print(arr[0, :] ) # 0 행 모든열
print(arr[: , 0] ) # 모든행 0 열
print(arr[0:2, :-1] ) #0 행~1 행, 처음부터 마지막열까지
[0 1 2 3]
[0 4]
[[0 1 2]
 [4 5 6]]
In [44]:
arr = np.array([1, 2, 3, 4, 5]) # shallow copy
x = arr
arr[0] = 42

print(arr)
print(x)
[42  2  3  4  5]
[42  2  3  4  5]
In [46]:
arr = np.array([1, 2, 3, 4, 5]) #실제 복사(deep copy)하려면 object.copy()를 사
x = arr.copy()
arr[0] = 42

print(arr)
print(x)
[42  2  3  4  5]
[1 2 3 4 5]
In [50]:
arr = np.array([[1,2,3],[4,5,6]])

print(arr)
print(arr.T) #배열 전치
[[1 2 3]
 [4 5 6]]
[[1 4]
 [2 5]
 [3 6]]
In [55]:
qr = np.arange(18).reshape(3,6) #arange arrary range 라는 뜻으로 0부터 까지  reshape 배열을 다시 3행 6열로 배열
print(qr)
[[ 0  1  2  3  4  5]
 [ 6  7  8  9 10 11]
 [12 13 14 15 16 17]]
In [120]:
import matplotlib.pyplot as plt  #그래프의 기본

xpoints = np.array(['Mon','Tue','Web',5,6])
ypoints = np.array([1,7,6,8,40])

plt.rc('font',family='Malgun Gothic')

plt.plot(xpoints, ypoints,'r+') #matplotlib라는 라이브러리에서 plot이라는 것으로 값을 넣음
plt.title('해happy point')
plt.xlabel('week')
plt.ylabel('bad')
plt.show()
In [115]:
import matplotlib.font_manager as fm

# font_list = fm.fontManager.ttflist
# for f in font_list :
#     print (f)

# font_list = fm.findSystemFonts(fontext='ttf')
# for f in font_list :
#     print(f)
In [127]:
import random
a = np.random.randint(0, 10, (2, 3))
print(a)
np.savetxt("./data/score.csv",a)
[[1 4 8]
 [9 5 5]]
In [128]:
b = np.loadtxt('./data/score.csv', np.int32)
print(b)
xpoint = np.array(b[0])
ypoint = np.array(b[1])

plt.plot(xpoint, ypoint,'r+')
plt.show()
[[1 4 8]
 [9 5 5]]
In [194]:
import requests
from bs4 import BeautifulSoup
response = requests.get("")
html_doc = response.text
soup = BeautifulSoup(html_doc, "html.parser")  #BeautifulSoup이란 str을 html 문서로 변경해주는 것
# print(html_doc)

tag = soup.select_one('div')
print(tag)
# new_list = tag.select('#cbox_module_wai_u_cbox_content_wrap_tabpanel > ul > li.u_cbox_comment.cbox_module__comment_430607834._user_id_no_3RtYo > div.u_cbox_comment_box > div > div.u_cbox_text_wrap > span.u_cbox_contents')
# news_list = tag.select('span.article-title ')
# for n in news_list :
#     print(n.get_text())
    
# soup.find_all('span',{'class' : 'article-title'})
---------------------------------------------------------------------------
MissingSchema                             Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_7512/2676280686.py in <module>
      1 import requests
      2 from bs4 import BeautifulSoup
----> 3 response = requests.get("")
      4 html_doc = response.text
      5 soup = BeautifulSoup(html_doc, "html.parser")  #BeautifulSoup이란 str을 html 문서로 변경해주는 것

~\anaconda3\lib\site-packages\requests\api.py in get(url, params, **kwargs)
     73     """
     74 
---> 75     return request('get', url, params=params, **kwargs)
     76 
     77 

~\anaconda3\lib\site-packages\requests\api.py in request(method, url, **kwargs)
     59     # cases, and look like a memory leak in others.
     60     with sessions.Session() as session:
---> 61         return session.request(method=method, url=url, **kwargs)
     62 
     63 

~\anaconda3\lib\site-packages\requests\sessions.py in request(self, method, url, params, data, headers, cookies, files, auth, timeout, allow_redirects, proxies, hooks, stream, verify, cert, json)
    526             hooks=hooks,
    527         )
--> 528         prep = self.prepare_request(req)
    529 
    530         proxies = proxies or {}

~\anaconda3\lib\site-packages\requests\sessions.py in prepare_request(self, request)
    454 
    455         p = PreparedRequest()
--> 456         p.prepare(
    457             method=request.method.upper(),
    458             url=request.url,

~\anaconda3\lib\site-packages\requests\models.py in prepare(self, method, url, headers, files, data, params, auth, cookies, hooks, json)
    314 
    315         self.prepare_method(method)
--> 316         self.prepare_url(url, params)
    317         self.prepare_headers(headers)
    318         self.prepare_cookies(cookies)

~\anaconda3\lib\site-packages\requests\models.py in prepare_url(self, url, params)
    388             error = error.format(to_native_string(url, 'utf8'))
    389 
--> 390             raise MissingSchema(error)
    391 
    392         if not host:

MissingSchema: Invalid URL '': No schema supplied. Perhaps you meant http://?
In [177]:
# ! pip install wordcloud
# ! conda install wordcloud = 편법(?)
# ! conda install -c conda-forge wordcloud 안되면 프롬포트에 들어가서 설치

import matplotlib.pyplot as plt
from wordcloud import WordCloud, STOPWORDS
import numpy as np
from PIL import Image

text = """
인스타로 몰래 보는 너의 하루들
누가 봐도 헤어진 티를 내
팔로우 다 끊고서 좋아요는 왜 눌렀니
참 바보 같은 사람이야
잘 먹지도 못하는 술은 왜 매일 마시고
늘 예쁜 얼굴 많이 야위었어
혼자 있으면 나도 그래
술이 없으면 못 자고 많이 괴로워해
이럴 거면 우리 미친 척하고 다시 만날까 봐
다시 시작할까 봐
친구들 만나는 거 그렇게 좋아하면서
집에만 있니 더 우울하게
혼자 있으면 나도 그래
누구도 만나기 싫어 숨고만 싶은데
이럴 거면 우리 미친 척하고 다시 만날까 봐
다시 시작할까 봐
못 잊을 거야 너와 추억한 지난날들을
난 아직까지도 너무나 선명해
그렇게 선명한 만큼 지키고픈 우리 기억들이
잊혀지는 게 정말 많이 두려워
혼자 있으면 나도 그래
늘 혼자 센척했지만 많이 두려워해
이럴 거면 우리 미친 척하고 다시 만날까 봐
다시 시작할까 봐
우리 여기서 끝나면 안 돼
"""

# print(STOPWORDS)
# 제외하고 싶은 단어 추가
spword = set(STOPWORDS)
spword.discard('k')
spword.discard('as')
spword.discard('an')
print(spword)
{'otherwise', "you'd", "couldn't", "they'd", "wasn't", 'be', "weren't", "shan't", 'him', "where's", 'above', 'on', 'com', "we'd", 'also', 'each', 'any', 'what', 'too', "i'm", 'nor', "can't", 'most', "didn't", "you're", 'until', 'below', 'are', 'so', 'the', "you've", 'just', 'of', 'should', 'some', 'have', "why's", 'when', 'only', 'we', "we're", 'how', 'into', 'did', 'both', 'ever', 'himself', 'themselves', 'by', 'r', 'who', 'my', 'she', 'here', 'since', 'therefore', 'a', "mustn't", 'get', "there's", 'between', 'off', 'do', "that's", "she'll", 'like', 'during', "i'd", 'to', "they're", "who's", 'this', 'up', 'myself', "i'll", 'own', 'hence', 'all', 'but', 'over', 'yourselves', 'and', 'or', 'does', 'why', 'from', 'ourselves', "he'll", 'was', 'such', 'is', 'very', 'could', "how's", 'before', 'these', 'being', 'they', "i've", "hasn't", "he'd", "you'll", 'you', 'if', "what's", 'where', 'me', 'i', 'itself', "let's", "hadn't", 'because', 'in', 'other', 'were', 'against', 'ours', "shouldn't", "we've", 'herself', "it's", 'them', 'your', "she'd", "haven't", "they'll", "when's", "here's", 'than', 'which', 'after', 'with', 'more', 'having', 'else', 'our', 'there', 'under', 'then', 'theirs', 'their', 'no', 'cannot', "doesn't", 'has', "isn't", "they've", 'while', 'same', "won't", 'that', 'out', 'those', "she's", 'its', "don't", 'few', 'it', 'yourself', 'shall', 'at', 'he', 'not', 'his', 'again', 'can', 'through', "aren't", 'hers', 'been', "he's", 'for', 'had', 'http', 'www', 'once', 'ought', 'would', 'am', "we'll", "wouldn't", 'further', 'down', 'yours', 'whom', 'however', 'doing', 'her', 'about'}
In [181]:
mask = np.array(Image.open('data/mask.png'))

wordcloud = WordCloud(max_font_size=200,
                      stopwords=spword, #많이 사용하는 단어는 제외
                      background_color= '#FFFFFF',
                      colormap='PRGn',
                      mask=mask,
                      font_path = './data/BMJUA_ttf.ttf',
                      width=1200,
                      height=1200).generate(text)
                      
In [182]:
plt.figure(figsize=(10,8))
plt.imshow(wordcloud)
plt.axis('off')

plt.show()
728x90
반응형