gpt4 book ai didi

python - pandas 情节时间序列-出现奇怪的线

转载 作者:行者123 更新时间:2023-11-30 22:08:16 25 4
gpt4 key购买 nike

我正在处理汇率数据,结果非常奇怪,图表中出现了未完成的线条。

我已经阅读了不同的示例,遵循了这些示例,但仍然无法摆脱这些线条。

有人知道我的代码有什么问题吗?感谢您的帮助。

enter image description here

df = df[['PRICE', 'TIME']]
start_time = '2018-08-01 19:50:00'
end_time = '2018-08-01 20:10:00'

df = df[(df['TIME'] > start_time) & (df['TIME'] <= end_time)]
df = df.set_index('TIME')

plt.figure(figsize = (18,9))
plt.plot(pd.to_datetime(df.index),df["PRICE"])
plt.xlabel('Time',fontsize=18)
plt.ylabel('Mid Price',fontsize=18)

如果需要任何数据,我将 csv 文件保存在 Google Drive https://drive.google.com/file/d/1ANybvOKeUYIhXxtm97VNT88SI8z2OWjV/view?usp=sharing

最佳答案

使用了您提供的相同数据

您需要添加df = df.sort_values(['TIME'], ascending=[True])

代码:

df = df[(df['TIME'] > start_time) & (df['TIME'] <= end_time)]
# df = df.drop_duplicates('TIME')
df = df.sort_values(['TIME'], ascending=[True])
df = df.set_index('TIME')

plt.figure(figsize=(18, 9))
plt.plot(pd.to_datetime(df.index), df["PRICE"])
plt.xlabel('Time', fontsize=18)
plt.ylabel('Mid Price', fontsize=18)

plt.show()

输出:

enter image description here

关于python - pandas 情节时间序列-出现奇怪的线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52217438/

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