我有一个来自网站的数据框,并将前几行用作Date. 它向我展示了一个 Df ,Yr_Mn_Dy但它看起来不错,所以我想将其更改为Dates.
df = pd.read_csv('https://raw.githubusercontent.com/guipsamora/pandas_exercises/master/06_Stats/Wind_Stats/wind.data', sep='\s+', parse_dates = [[0,1,2]] )
df.head()
Yr_Mo_Dy RPT ... BEL MAL
0 2061-01-01 15.04 ... 18.50 15.04
1 2061-01-02 14.71 ... 17.54 13.83
2 2061-01-03 18.50 ... 12.75 12.71
3 2061-01-04 10.58 ... 5.46 10.88
4 2061-01-05 13.33 ... 12.92 11.83
我一一使用了2种不同的方法
1. df.rename(columns= {'Yr_Mo_Dy': 'Dates'}) # it does not work. it is not changing the columns names to Dates
and
2. df.columns.values[0]='Dates' # it changes the values when used with df.head() but throws Key error for Dates
1.为什么第一种方法不改值重命名列?
2. 用第二种方法改变值后,为什么会抛出DatesKey错误?
拉风的咖菲猫
相关分类