Programming84 [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. [python] Pandas Filtering and Ordering 주피터 노트북을 사용해서 filtering 과 ordering 사용 1. import pandas import import pandas as pd 2. csv 파일 불러오기 In [2]:3. #폴더에서 데이터 불러오기 df = pd.read_csv(f'/Users/grace/Desktop/Alex/world_population.csv') df df[df['Rank'] 컬럼을 찾고 싶으면 axis 1 추가 필요) #'Continent','CCA3'만 filter하는 테이블 만들기(item, axis 사용) df2.filter(items = ['Continent','CCA3'], axis = 1) Out[26]: - axis = 0 (가로 행에서의 정보를 찾을 때) #'Zimbabwe'만 filter하는 테.. 2023. 5. 31. [파이썬] 자동 파일 분류 프로그램 만들기 python을 사용해서 자동으로 파일을 분류해주는 프로그램을 만들어봅니다. 1. anaconda jupyter 노트북을 사용해서 os 와 shutil 라이브러리를 불러와봅니다. import os, shutil #operating sytem, and high level operation on our files 1) os : used to load files into the notebook 2) shutil: 고수준의 파일을 연산함, 예를 들어 copy, create, delete, Remote 등 2. path 정해주기(고수준 연산을 하고 싶은 파일 명을 잡아준다.) In [7] path = f'/Users/grace/Desktop/파일명' In [8]: 3. 파일명 정해주기 file_name= os.li.. 2023. 5. 31. 이전 1 2 3 4 5 ··· 21 다음