-- 어제 배운 내용 --
df.describe(include="object")
df.isnull().sum()
df.isnull().mean()
(1) 기술통계 보기 - 2
df.describe(include="all")
frequency, top 값 등을 확인
(2) 범주형 데이터는 object 외에도 boolean 등의 형식으로도 구성.
(3) nunique 값 구하기
df.nunique()
(4) exclude로 특정 값 제외하고도 가능
(1) 괄호의 의미
df.groupby("origin")["mpg"].mean()
mpg라는 컬럼으로 한정한다는 의미.
(2) pivot_table
aggfunc: AggFuncType='mean'
= 평균이 기본값이라는 의미
(3) barplot 으로 합계 값 구하기
sns.barplot(data=df, x="origin", y="mpg", hue="cylinders", estimator=sum)
estimator=sum이 해당 기능을 실행
(4) groupby 를 통해 시각화에 대한 값을 구하기
df.groupby(by=["origin","cylinders"])["mpg"].mean()
df.groupby("origin")["mpg"].describe()에서 소괄호, 중괄호가 각각 갖는 의미=origin 값 별로 mpg 값에 대한 통계를 구한다는 의미.
by라는 argument를 parameter로 넘김. 두 개의 값을 할당하지 않도록 유의.
(5) unstack
마지막 인덱스에 있는 값(=column 등)을 끌어올려서 볼 수 있음. (멀티인덱스와 무관하게)
(6) pd.pivot_table 을 통해 시각화에 대한 값을 구하기
pd.pivot_table(data=df, index="origin", columns="cylinders", values="mpg")
(6) pivot_table은 연산을 하고, pivot은 연산을 하지 않는다.
(1) 막대그래프의 단점
(2) boxenplot
(3) scatterplot
sns.scatterplot(data=df, x="origin", y="mpg")
산점도는 빈도수 확인이 어렵다는 단점이 있다.
(4) stripplot
(5) swarmplot
(6) catplot
sns.catplot(data=df, x="origin", y="mpg", kind="violin", col="cylinders", col_wrap=3)
(7) countplot
유의점: countplot은 서브플롯 생성 시, x, y값 중 둘 중 한개만 할당해야 함
(1) 로봇 배제 표준
time.sleep()
(1) url 가져오기
item_code = "035720"
item_name = "카카오"
page_no = 1
item_code = "https://finance.naver.com/item/main.naver?code=035720"
pd.read_html(url)
(2) read_html을 이용하여 데이터 가져오기
df = table[0]
df
table이라는 변수에 read_html에서 가져온 데이터 넣기
조건: 0번째 인덱스 값을 가진 데이터만 넣어주었음
(2) display로 출력
temp_list = []
for news in table:
temp_list.append(news)
display(news)
temp_list라는 변수에 가져온 테이블의 모든 내용들을 넣어줌
(3) 페이지컬럼 인덱싱
cols = df.columns
cols
temp_list = []
for news in table[:-1]:
news.columns = cols
temp_list.append(news)
display(news)
page 제거
(4) 인덱스 번호 초기화
df_news.reset_index(drop=True)
(5) 비트와이즈 연산 (~)
------ 모르는 점 ------
(1) groupby에서 by의 역할
(2) dropna 함수:
https://cosmosproject.tistory.com/308
(3) 얕은 복사와 깊은 복사
(4) f-string: https://www.daleseo.com/python-f-strings/
------ 퀴즈 오답노트 ------
(1) value_counts(): 하나의 변수에 대한 빈도수를 구한다.
(2) scatterplot() - 수치형 변수 표현 O, 범주형 변수 표현 X
(3) robots.txt는 검색엔진에게 수집해도 되는 페이지인지를 알려준다 (페이지, 에이전트 정보 등)
------ 논문 인사이트 ------