Python/Pandas
pandas dataframe 의 column 이름 변경하기 여러 방법
節稅美人
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(' ','_')