[英]Dataframe changing question with time series data with pandas
如果您只想查看 plot 数据 pandas 应该为您处理您的日期时间,假设它们是日期时间格式而不是字符串。
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
event_time = pd.to_datetime('2024-04-28T07:52:00')
date_time = pd.date_range(event_time, periods=24, freq=pd.to_timedelta(10, 'minute'))
df = pd.DataFrame({'date_time': date_time, 'change': np.random.normal(size=len(date_time))})
ax = df.plot(x='date_time', y='change')
plt.show()
但是,如果您想从 x 轴上删除特定时间并从零开始计数,您可以使用索引作为 x 轴:
df['_index'] = df.index
ax = df.plot(x='_index', y='change')
plt.show()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.