gpt4 book ai didi

python - 如何获取时间序列的x轴标签? ( python 、 Pandas )

转载 作者:行者123 更新时间:2023-12-01 09:16:42 25 4
gpt4 key购买 nike

我正在尝试在 pandas 中绘制时间序列数据框。该图看起来不错,但 x 轴上没有标签:

picture of the timeseries plot

有人可以对此提出建议吗?我的代码

import pandas as pd  
from pandas import Series
import matplotlib.pyplot as plt

df = pd.read_csv("coindeskbpi.csv", parse_dates =True , index_col = 'Date',
dayfirst=True)

df.head()

df.plot()
plt.show()

数据看起来像这样

                        Open     High      Low    Close
Date
2017-11-01 00:00:00 6447.67 6750.17 6357.91 6750.17
2017-11-02 00:00:00 6750.17 7355.35 6745.96 7030.00
2017-11-03 00:00:00 7030.00 7454.04 6942.29 7161.45
2017-11-04 00:00:00 7161.45 7503.72 6994.88 7387.00
2017-11-05 00:00:00 7387.00 7601.53 7297.58 7382.45
<class 'pandas.core.frame.DataFrame'>

有 94 个条目。

最佳答案

尝试这样:

df = pd.read_csv("coindeskbpi.csv", sep=',') #or the sep you are using
df.set_index('Date', inplace=True)
df.plot()
plt.show()

enter image description here

关于python - 如何获取时间序列的x轴标签? ( python 、 Pandas ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51188674/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com