pandas dataframe 의 column 이름 변경하기 여러 방법
- Python/Pandas
- 2018. 6. 18. 21:06
Pandas DataFrame 에 있는 column 이름 변경¶
In [1]:
import pandas as pd
In [2]:
ufo = pd.read_csv('http://bit.ly/uforeports')
In [4]:
ufo.head()
Out[4]:
In [5]:
ufo.columns
Out[5]:
In [6]:
ufo.rename(columns={'Colors Reported':'Colors_Reported', 'Shape Reported':'Shape_Reported'}, inplace=True)
In [7]:
ufo.columns
Out[7]:
In [8]:
ufo_cols = ['city','colors reported', 'shape reported', 'state','time']
In [9]:
ufo.columns = ufo_cols
In [11]:
ufo.head()
Out[11]:
In [14]:
ufo = pd.read_csv('http://bit.ly/uforeports', names=ufo_cols, header=0)
In [15]:
ufo.head()
Out[15]:
In [16]:
ufo.columns = ufo.columns.str.replace(' ','_')
'Python > Pandas' 카테고리의 다른 글
pandas 커맨드 중 괄호()를 사용 하는 것과 그렇지 않는 것의 구분 (0) | 2018.06.17 |
---|---|
Pandas Dataframe 에서 seriese 선택하는 방법 (0) | 2018.06.17 |
pandas 표 불러 오기(헤더 없이, 컬럼 이름 지정) (0) | 2018.06.14 |
python and pandas datetime 과 to_datetime 활용 (0) | 2018.06.07 |