列日期(INDEX?)pandas不能在matplot中设置为y

时间:2017-05-16 16:44:54

标签: python pandas matplotlib

我的简单代码:

import pandas as pd
df = pd.DataFrame('data')

print(type(df))
print(df.columns)
print(df.head())

输出:

<class 'pandas.core.frame.DataFrame'>
Index(['Value'], dtype='object')
             Value
Date              
2010-03-31  965.95
2010-04-01  974.99
2010-04-06  963.82
2010-04-07  968.23
2010-04-08  972.51

我的问题是,如何访问Date列?我想将它用于matplot Y轴:

from matplotlib import pyplot as plt

plt.scatter(x, y = df['Date']))

问题是,我无法访问它。感谢

1 个答案:

答案 0 :(得分:2)

让我们试试:

df.index = pd.to_datetime(df.index)

plt.scatter(df['Value'],df.index)

enter image description here