본문 바로가기

DataScience90

데이터프레임에 "특정단어"가 들어가있는지 여부 pd.str.contains() 데이터 중 choice_description 값에 Vegetables 들어가지 않는 경우의 갯수를 출력하라 df.loc[ df["choice_description"].str.contains("Vegetables", case =False) == False, ] 혹은, df.loc[ ~df["choice_description"].str.contains("Vegetables",case =False), ] # case = False = 대문자 , 소문자 상관없이 가져와라 2022. 11. 29.
pd.read_csv(thousands= ','), 차원이 다른 데이터를 차트로, 데이터프레임에서 데이터값의 콤마제거 해당 데이터 프레임에서 0세부터 100세 까지 나이대 별로 몇명이 있는지 시각화를 한다면 df2 = df.loc[ df["행정구역"].str.contains("삼청동"), "2019년07월_계_0세" : ].values # values 로 컬럼을 제외한 값만 가져온다. [in]df2 [out]array([[ 7, 9, 13, 12, 11, 11, 9, 11, 20, 18, 18, 23, 23, 19, 17, 16, 20, 25, 25, 27, 22, 35, 34, 29, 42, 38, 38, 32, 31, 36, 53, 32, 29, 42, 45, 29, 45, 50, 45, 52, 43, 36, 34, 29, 35, 33, 41, 37, 46, 48, 44, 47, 33, 46, 41, 40, 44, .. 2022. 11. 29.
Matplotlip Heat Maps : 밀도차트, 한글처리 Heat Maps : 밀도를 나타내는데 좋다.¶ In [304]: # displ 과 comb 의 관계를 나타내되, # 데이터가 많고 적음을 표시할 수 있도록 # heat map 으로 시각화 In [349]: plt.colormaps() Out[349]: ['magma', 'inferno', 'plasma', 'viridis', 'cividis', 'twilight', 'twilight_shifted', 'turbo', 'Blues', 'BrBG', 'BuGn', 'BuPu', 'CMRmap', 'GnBu',.. 2022. 11. 28.
Matplotlip 두 컬럼간의 관계(비례,반비례,관계없음) Bivariate (여러개의 변수) Visualization 방법¶ Scatterplots¶ In [246]: import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sb %matplotlib inline In [ ]: # 두 컬럼간의 관계! 를 차트로 나타내는 방법 In [247]: # 관계란??? 비례관계, 반비례관계, 아무관계 없음.. 이 3가지를 말한다. In [248]: pd.read_csv("../data/fuel_econ.csv") Out[248]: id make model year VClass drive trans fuelType cylinders displ pv2 pv4 city UCi.. 2022. 11. 28.
Matplotlip 히스토그램, 갯수범위지정, bins, subplot # 구간을 설정하여, 해당 구간에 포함되는 데이터가 몇개인지(갯수) # 세는 차트를 히스토그램이라고 한다. # 구간을, bin 이라고 부른다. # 구간이 여러개니까, bins 라고 부른다. # 히스토그램은, 똑같은 데이터를 가지고, # bin을 어떻게 잡느냐에 따라서, 차트 모양이 달라져서, # 해석을 다르게 할 수 도있다. df['speed'].describe() count 807.000000 mean 65.830235 std 27.736838 min 5.000000 25% 45.000000 50% 65.000000 75% 85.000000 max 160.000000 Name: speed, dtype: float64 plt.hist(data = df, x = 'speed') plt.show() # bi.. 2022. 11. 28.
Matplotlip&seaborn 기본적인 차트, 파이차트 PYTHON PROGRAMMING FUNDAMENTALS¶ In [ ]: # 해당 내용은 numpy ,pandas 와 연계되므로 사전 내용을 숙지 후 보시기를 바랍니다. In [ ]: Tidy Data¶ each variable is a column each observation is a row each type of observational unit is a table In [ ]: In [ ]: 다음 토픽을 설명합니다. Matplotlib ref: https://matplotlib.org/gallery.html#scales https://seaborn.pydata.org/ In [ ]: 가장기본적인 Plot¶ In [1]: import matplotlib.pyplot as plt In [2]: imp.. 2022. 11. 28.
Pandas concat(), merge() 여러 데이터 프레임을 하나로 합치는 방법 CONCATENATING AND MERGING¶ Reference: https://pandas.pydata.org/pandas-docs/stable/merging.html In [4]: import pandas as pd In [5]: df1 = pd.DataFrame({'A': ['A0', 'A1', 'A2', 'A3'], 'B': ['B0', 'B1', 'B2', 'B3'], 'C': ['C0', 'C1', 'C2', 'C3'], 'D': ['D0', '.. 2022. 11. 25.
Pandas 데이터프레임 오름차순, 내림차순 정렬 .Sort_values() ,sort_index() SORTING AND ORDERING¶ In [41]: df = pd.DataFrame({'Employee ID':[111, 222, 333, 444], 'Employee Name':['Chanel', 'Steve', 'Mitch', 'Bird'], 'Salary [$/h]':[35, 29, 38, 20], 'Years of Experience':[3, 4 ,9, 1]}) df Out[41]: Employee ID Employee Name Salary [$/h] Years of Experience 0 111 Chanel 35 3 1 222 Steve 29 4 2 333 Mitch 38 9 3.. 2022. 11. 25.
Pandas 사용자 정의 함수사용 .apply(), 판다스내장.str라이브러리 PANDAS OPERATIONS¶ In [2]: import pandas as pd In [3]: df = pd.DataFrame({'Employee ID':[111, 222, 333, 444], 'Employee Name':['Chanel', 'Steve', 'Mitch', 'Bird'], 'Salary [$/h]':[35, 29, 38, 20], 'Years of Experience':[3, 4 ,9, 1]}) df Out[3]: Employee ID Employee Name Salary [$/h] Years of Experience 0 111 Chanel 35 3 1 222 Steve .. 2022. 11. 25.
Pandas 카테고리컬, groupby(), 특정 데이터 가져오기 실습¶ In [1]: import pandas as pd import numpy as np # 책 제목과 작가, 그리고 유저별 별점 데이터가 있다. books = pd.Series(data = ['Great Expectations', 'Of Mice and Men', 'Romeo and Juliet', 'The Time Machine', 'Alice in Wonderland' ]) authors = pd.Series(data = ['Charles Dickens', 'John Steinbeck', 'William Shakespeare', ' H. G. Wells', 'Le.. 2022. 11. 24.
Pandas NaN을 처리하는 전략 dropna(), fillna() Dealing with NaN¶ In [150]: # We create a list of Python dictionaries items2 = [{'bikes': 20, 'pants': 30, 'watches': 35, 'shirts': 15, 'shoes':8, 'suits':45}, {'watches': 10, 'glasses': 50, 'bikes': 15, 'pants':5, 'shirts': 2, 'shoes':5, 'suits':7}, {'bikes': 20, 'pants': 30, .. 2022. 11. 24.
Pandas CSV파일불러오기, .describe() 통계, .info()정보 winemag-data-150k-v2.csv 파일을 reviews 로 읽는다. In [1]: import pandas as pd In [ ]: # 파일을 불러올때 필요없는 열을 안보여주는 방법 Unnamed 열을 없애기. In [4]: pd.read_csv('../data/winemag-data_first150k.csv') ##../ => 이전폴더로 이동, 여기서 tap 을 누르면 자동으로 폴더리스트가 보인다 Out[4]: Unnamed: 0 country description designation points price province region_1 region_2 variety winery 0 0 US This tremendous 100% varietal wine hails from .. 2022. 11. 24.