본문 바로가기

분류 전체보기100

[python] visualization pandas import pandas as pd import numpy as np import matplotlib.pyplot as plt In [37]: #불러오기 df = pd.read_csv(f'/Users/grace/Desktop/Alex/Ice Cream Ratings.csv') df Out[37]: DateFlavor RatingTexture RatingOverall Rating0123456 1/1/2022 0.223090 0.040220 0.600129 1/2/2022 0.635886 0.938476 0.106264 1/3/2022 0.442323 0.044154 0.598112 1/4/2022 0.389128 0.549676 0.489353 1/5/2022 0.386887 0.519439 0.98828.. 2023. 6. 1.
[python] merge, join, concatenate pandas import pandas as pd In [3]: #df1 생성하기 df1 = pd.read_csv(f'/Users/grace/Desktop/Alex/LOTR.csv') df1 Out[3]: FellowshipIDFirstNameSkills0123 1001 Frodo Hiding 1002 Samwise Gardening 1003 Gandalf Spells 1004 Pippin Fireworks #df2 생성하기 df2 = pd.read_csv(r"/Users/grace/Desktop/Alex/LOTR 2.csv") df2 Out[5]: FellowshipIDFirstNameAge01234 1001 Frodo 50 1002 Samwise 39 1006 Legolas 2931 1007 Elrond 6520 .. 2023. 6. 1.
[python] pandas group by and agg. function Group by and Aggregating In [1]: import pandas as pd df = pd.read_csv(f'/Users/grace/Desktop/Alex/Flavors.csv') df #group_by_frame = base flavor로 그룹짓기 group_by_frame= df.groupby('Base Flavor') #mean 구하기 group_by_frame.mean() #base flavor만 뽑아서 횟수 세기 group_by_frame.count() #base flavor만 뽑아서 sum group_by_frame.sum() - .agg에는 dictionary가 필요함 #base flavor만 뽑아서 Flavor Rating이랑 Texture Rating의 ['mean',.. 2023. 6. 1.
[python] pandas indexes import pandas as pd In [3]: #csv 불러오기 df = pd.read_csv(f'/Users/grace/Desktop/Alex/world_population.csv') df #csv 불러오기 - Country로 인덱스 잡기 df = pd.read_csv(f'/Users/grace/Desktop/Alex/world_population.csv',index_col='Country') df - reset_index(inplace = True ) 다른 변수에 저장하지 않는 다는 뜻 #인덱스 다시 reset하기 df.reset_index(inplace=True) df - 재설정한 index를 save 하고 싶으면 Inplace = True 를 꼭 넣어줘야 함 #'Country'를 index다시.. 2023. 6. 1.