본문 바로가기
728x90

pandas6

판다스 groupby 활용법_Day 32 When should I use a 'groupby' in pandas? import pandas as pd drinks = pd.read_csv("http://bit.ly/drinksbycountry") drinks.head() drinks.beer_servings.mean() 106.16062176165804 drinks.groupby('continent').beer_servings.mean() continent Africa 61.471698 Asia 37.045455 Europe 193.777778 North America 145.434783 Oceania 89.687500 South America 175.083333 Name: beer_servings, dtype: float64 drinks.gr.. 2021. 2. 16.
Data Slice , loc , iloc 굉장히 햇갈리는 1차원배열, 2차원배열에서의 슬라이스 정리해보자 1차원 배열 DataFrame 슬라이스 1차원 배열 DataFrame 슬라이스(2) 인덱스 loc, iloc 1. 행번호(row number)로 선택하는 방법(.iloc) 2. label , 인덱스 조건표현으로 선택하는 방법 (.loc) 2차원 배열 DataFrame 슬라이스 2차원 배열 DataFrame 열조회 2021. 1. 5.
Data Manipulation_Day3(5)_pipe & chaining chaining 연속적으로 진행되는 코드를 조금더 깔끔하게 정리하는 방법 예) (before) df = a(df) df = b(df) df = c(df) (after) df = df.a.b.c() pipe 판다스 파이프 모르겠다 이해안됨 출처 : pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.pipe.html 2021. 1. 4.
Data Manipulation,concat,merge,melt_Day3 Data Science / Section 1 / Sprint 1 / 20.12.30 Lecture Pandas concat Concat = 붙인다 merge = 합친다 x,y는 각각 데이터셋 pd.concat([x,y]) #axis = 0 이 기본값 , #상하로 붙인다 pd.concat([x,y], axis = 1) #좌우로 붙인다 결측치는 NaN으로 채워진다 df = pd.concat([df.reset_index(), df2['종목'].head(6)], axis = 1) df.reset_index() => 좌측 index값을 리셋 (0,1,2,3,4,5~)로 세팅하고, 기존 인덱스값은 우측으로 한줄미뤄서 세팅 df2['종목'].head(6) => 7번행은 사용하지않을 항목이기때문에 head(6)으로 범.. 2020. 12. 30.
25 pandas tricks_Day3(2) Data Science / Section 1 / Sprint 1 / 20.12.30 Top 25 Pandas tricks Pandas DataFrame 활용 https://youtu.be/RlIiVeig3hc nbviewer.jupyter.org/github/justmarkham/pandas-videos/blob/master/top_25_pandas_tricks.ipynb Jupyter Notebook Viewer Now if you need a much larger DataFrame, the above method will require way too much typing. In that case, you can use NumPy's random.rand() function, tell it the nu.. 2020. 12. 30.
시작,EDA,Data Science_Day1 Data Science / Section 1 / Sprint 1 / 20.12.28 Warm up 코드스테이츠 AI 첫 날 1) 블로그에 나의 스토리를 남기자 2) TIL TIW 만들기 Today I learned 보다 더 중요한 Today I Wondered 3) 7시 이후 줌 켜놓고 '모각코' Lecture EDA 탐색적 데이터 분석 '데이터를 가공하기 전에 주어진 자료 자체만으로 해석, 의미를 알아내는 방법' Github Fork & PR Close & Commit repository : github에서 특정 파일을 저장하는 폴더 / repo df = pd.read_csv(ktng_data_url) df.head() #제목포함 첫 5줄 보여주기 column_headers = ['분기', '매출액',.. 2020. 12. 28.
728x90