【发布时间】:2018-04-02 18:24:48
【问题描述】:
我正在尝试更改我的数据框列名称,我尝试了两种方法,但都没有奏效。 这是我的代码;
方法一:
def func():
energy=pd.ExcelFile('Energy Indicators.xls').parse('Energy')
energy=energy.iloc[16:][['Environmental Indicators: Energy','Unnamed:3','Unnamed: 4','Unnamed: 5']].copy() energy.columns()=['Country',
'Energy Supply', 'Energy Supply per Capita', '%Renewable']
return energy
方法二:
def func():
energy=pd.ExcelFile('Energy Indicators.xls').parse('Energy')
energy=energy.iloc[16:][['Environmental Indicators: Energy','Unnamed: 3','Unnamed: 4','Unnamed: 5']].copy()
return energy.rename(columns={'Environmental Indicators: Energy': 'Country', 'Unnamed: 3': 'Energy Supply',
'Unnamed: 4': 'Energy Supply per Capita', 'Unnamed: 5': '% Renewable'}, inplace=True)
它们都返回一个 NoneType 对象。
这是我正在处理的 .xls 文件:https://drive.google.com/file/d/0B80lepon1RrYeDRNQVFWYVVENHM/view?usp=sharing
【问题讨论】: