DF1:
Name
Date
2012-11-26 a
2012-11-27 a
DF2:
Date Name
2012-11-26 a
2012-11-27 a
如何从df2
获取df1
?
我试图使用:
df1.reset_index(level=0,inplace=True)
我想要的不匹配。
答案 0 :(得分:1)
使用reset_index
:
df2 = df1.reset_index()
或者:
df1.reset_index(inplace=True)
样品:
import pandas as pd
df1 = pd.DataFrame({'Name': {'2012-11-27': 'a', '2012-11-26': 'a'}})
df1.index.name = 'Date'
print (df1)
Name
Date
2012-11-26 a
2012-11-27 a
df2 = df1.reset_index()
print (df2)
Date Name
0 2012-11-26 a
1 2012-11-27 a
df1.reset_index(inplace=True)
print (df1)
Date Name
0 2012-11-26 a
1 2012-11-27 a