Python39

pandas Tricks_11👉🏻 'Reshaping → stack() & unstack()' (Kevin by DataSchool) Q. 데이터를 재구조화하는 방법? A. stack() & unstack() 사용! 🙂 ¶ stack() docu https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.stack.html DataFrame.stack(level=- 1, dropna=True) 'Stack the prescribed level(s) from columns to index. Return a reshaped DataFrame or Series having a multi-level index with one or more new inner-most levels compared to the current DataFrame. The new inner-most levels are.. Python/Pandas&Numpy 2022. 4. 14.
pandas Tricks_09&10👉🏻 'EXPANDING → a string & a series of lists - into a DF' (Kevin by DataSchool) 😌 dataframe내의 data를 자유자재로 나누어 갖다 붙이고, 들어 있는 게 list면 따로 뽑아내서 갖다 붙이고 싶다면..? → 즉, dataframe 자체를 자유자재로 추가 정보를 붙여 확대하고 싶을 때 사용! ← 1. EXPANDING(1) - splitting a string into MULTIPLE COLUMNS Q) column 내의 string 문자열을 일정 기준으로 나누어 기존 dataframe에 갖다 붙이고 싶으면? A) .column_name.str method를 활용하여 split 적용 → expand = True df = pd.DataFrame({'name': ['Ryan Murphy Kim', 'Jane Doe Rhondall'], 'location': ['Los Angele.. Python/Pandas&Numpy 2022. 4. 14.
Python Basics(2). (from Coursera) 4) Working with Data in Python # Reading & Writing Files with Open * Reading Files with Open - open) provides a File object that contains the methods and attributes you need in order to read, save, and manipulate the file, the first parameter is the file path and file name / the second argument is mode(optional): default value is r - It is very important that the file is closed in the end. This .. Python/Fundamentals 2022. 4. 13.
pandas Tricks_08👉🏻 'missing values - dropna() & isna() (advanced)' (Kevin by DataSchool) * handling missing values는 preprocessing 단계의 일부로 하단 포스팅에서 일부 배웠다 ↓↓↓↓ - dropna, isnull, fillna - Data Preprocessing * concepts🤲 ⊙ Although EDA and Data Preprocessing are two distinct terms, they involve many overlapping subtasks. At times, they are even used interchangeably ⊙ → 즉! 모아진 raw data를 data.. sh-avid-learner.tistory.com Q) NaN 값이 몇%의 값으로 있는 지, NaN이 몇 % 이상 있는 비율 column만 선택해서 제거가 가능한지? A).. Python/Pandas&Numpy 2022. 4. 9.
concat & append & merge & join 👋 data는 무수히 여러 종류로 나누어져 있다(for 보안 & 효율성). 합치는 과정을 data preprocessing 과정에서 반드시 겪게 되는 데,, 어떤 case에 어떤 최적의 함수를 사용해야 할 지 이번 포스팅을 통해 총 네 가지! concat, append, merge, join에 대해서 알아보자 👉 docu list - concat) https://pandas.pydata.org/docs/reference/api/pandas.concat.html - append - dataframe) https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.append.html - append - series) https://pandas.pydata.o.. Python/Pandas&Numpy 2022. 4. 9.
Web Crawling(Scraping) 개요 + DOM 기초 🕵🏻 우리가 주어진 data는 대게 정돈된 structured data가 아닐 확률이 높다. 특히 web에 흩뿌려진 data를 가져오는 경우가 종종 있는데, 이 때 web scraping이라는 기법을 사용함! (개인적으로 너무 재밌는 web scraping 🏄🏻‍♀️) Q. Web Scraping vs. Web Crawling? ≫ web scraping은 우리가 찾을 'data'에 초점을 둔 것 / web crawling은 우리가 찾을 장소인 'url'에 초점을 둔 것. 대게 crawling과 scraping 과정을 병행한다. (web scraping is about extracting the data from one or more websites. While crawling is about findi.. Python/Web Crawling+Scraping 2022. 4. 5.
Python Basics(1). (from Coursera) 1) Python Basics # Types e.g) 11 (int) / 12.32 (float) - can check the specifics of floats 'sys.float_info' / "I love Python" (str) / True, False (bool) → By using the data type, we can see the actual data type (type(11) = int) → type casting) change the type of the expression (float(2), int(2.2), string(1), int(True) = 1) # Expressions & Variables → Expressions describe a type of operation the .. Python/Fundamentals 2022. 4. 4.
pandas Tricks_07👉🏻 'Filtering - isin & tilde(~)&nlargest' (Kevin by DataSchool) Q. dataframe 자체 내에 연산자를 써서 condition으로 data를 나눌 수 있다. 이 때 isin method & tilde를 써서 좀 더 깔끔하게! filtering 가능 A. condition에 isin method 사용, 그리고 tilde(~)를 condition 맨 앞에 붙이기 ∬ isin docu ∬ https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.isin.html DataFrame.isin(values) Q) 타이타닉호 탑승자 중 Southampton & Queenstown 출신 / 이 두 지역이 아닌 사람들 data filtering하기 > titanic dataset 준비 & 'embark_town' column .. Python/Pandas&Numpy 2022. 3. 31.
pandas Tricks_05 & 06👉🏻 'Create a DataFrame from the clipboard & Split a DataFrame into 2 random subsets' (Kevin by DataSchool) Q05) 빨리 한 dataframe을 만들고 싶을 때, 특히 연속하는 숫자, 문자 등 여러 일련의 data를 복붙해서 df로 만들고 싶다면? A) 👇 read_clipboard() 사용! pd.read_clipboard() ◈ read_clipboard docu ◈ https://pandas.pydata.org/docs/reference/api/pandas.read_clipboard.html 1> 원하는 일련의 표를 Google SpreadSheet나 Excel에 만든다 더보기 2> Ctrl + C! 3> read_clipboard() 입력하면 끝! df = pd.read_clipboard() 4> 완성! → index는 알아서 0부터 생성됨 → dtypes 결과 data의 속성에 맞게 자동적으로 dty.. Python/Pandas&Numpy 2022. 3. 30.
pandas Tricks_04 👉🏻 'Build a DataFrame from multiple files (row-wise & column-wise) ' (Kevin by DataSchool) Q. 여러 csv파일을 가져와 한 개의 dataframe에 나타내고 싶으면? A) 👇 glob package의 glob module 사용! from glob import glob ♣ glob docu 👇👇 ♣ https://docs.python.org/3/library/glob.html ▧ glob module ▧ "The glob module finds all the pathnames matching a specified pattern according to the rules used by the Unix shell, although results are returned in arbitrary order(그래서 glob쓰면 sorted() 추천!). No tilde expansion is done, b.. Python/Pandas&Numpy 2022. 3. 25.
map & applymap & apply(on dataframe & Series) 「pandas dataframe에서 유용하게 쓰이는 두 method 'apply' & 'applymap' & 'map' 에 대해서 알아보자」 (+추가로 Series에서의 apply method도 알아보자) ▩ pandas.DataFrame.apply ▩ docu 👉 https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.apply.html DataFrame.apply(func, axis=0, raw=False, result_type=None, args=(), **kwargs) "Apply a function along an axis of the DataFrame. Objects passed to the function are Series object.. Python/Pandas&Numpy 2022. 3. 25.
pandas Tricks_03 👉🏻 'Convert Strings→numbers ' (Kevin by DataSchool) Q. 숱하게 많이 보이는 string형 data type...! 하지만 우리는 계산을 위해서 무조건 수치형으로 바꿔야 한다.. 하지만 너무 많은 방법들이 있다. 어떤게 제일 효과적이고 좋은 방법일까? 이 포스팅으로 한 방에 해결하자..! A. 👉🏻 to_numeric 먼저 string type의 수를 모두 입력 (한 개는 -) df = pd.DataFrame({'col_one':['1.1','2.2','3.3'], 'col_two':['4.4','5.5','6.6'], 'col_three':['7,7','8.8','-']}) 1. astype() ♠astype() docu - https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.astype.htm.. Python/Pandas&Numpy 2022. 3. 25.