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다시 set 하기 inplace
df.set_index('Country', inplace = True)
df
- loc = location 로블럭스 기억하면서 loc 뒤에는 bracket이 나옴
#Albania 뽑기 loc
df.loc['Albania']
#index 다시 뽑기
df.reset_index(inplace = True)
- index를 두개 list로 만들어서 설정할 수도 있음
#Continent, Country로 다시 index 맞추기, 항상 inplace 필요
df.set_index(['Continent','Country'], inplace = True)
- index 다시 sort 하기
#index sort 하기
df.sort_index()
#첫번째 행 뽑기
df.iloc[1]
'Programming > python' 카테고리의 다른 글
[python] merge, join, concatenate pandas (1) | 2023.06.01 |
---|---|
[python] pandas group by and agg. function (2) | 2023.06.01 |
[python] Pandas Filtering and Ordering (0) | 2023.05.31 |
[파이썬] 자동 파일 분류 프로그램 만들기 (0) | 2023.05.31 |
[알고리즘] 파이썬 문법 (0) | 2023.04.10 |