python读取csv画图datetime_python – CSV数据(Timestamp和事件)的时间表绘图:x-label常量...
(這個問題可以單獨閱讀,但是是續集:
Timeseries from CSV data (Timestamp and events))
我想通過使用python的熊貓模塊(見下面的鏈接)的時間表表示,可視化CSV數據(從2個文件),如下所示.
df1的樣本數據:
TIMESTAMP eventid
0 2017-03-20 02:38:24 1
1 2017-03-21 05:59:41 1
2 2017-03-23 12:59:58 1
3 2017-03-24 01:00:07 1
4 2017-03-27 03:00:13 1
‘eventid’列總是包含值1,我試圖顯示數據集中每一天的事件總和.
第二個數據集df0具有相似的結構,但只包含零:
df0的樣本數據:
TIMESTAMP eventid
0 2017-03-21 01:38:24 0
1 2017-03-21 03:59:41 0
2 2017-03-22 11:59:58 0
3 2017-03-24 01:03:07 0
4 2017-03-26 03:50:13 0
x軸標簽只顯示相同的日期,我的問題是:如何顯示不同的日期? (什么導致在x標簽上多次顯示相同的日期?)
腳本到目前為止
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
df1 = pd.read_csv('timestamp01.csv', parse_dates=True, index_col='TIMESTAMP')
df0 = pd.read_csv('timestamp00.csv', parse_dates=True, index_col='TIMESTAMP')
f, (ax1, ax2) = plt.subplots(1, 2)
ax1.plot(df0.resample('D').size())
ax1.set_xlim([pd.to_datetime('2017-01-27'), pd.to_datetime('2017-04-30')])
ax1.xaxis.set_major_formatter(ticker.FixedFormatter
(df0.index.strftime('%Y-%m-%d')))
plt.setp(ax1.xaxis.get_majorticklabels(), rotation=15)
ax2.plot(df1.resample('D').size())
ax2.set_xlim([pd.to_datetime('2017-03-22'), pd.to_datetime('2017-04-29')])
ax2.xaxis.set_major_formatter(ticker.FixedFormatter(df1.index.strftime
('%Y-%m-%d')))
plt.setp(ax2.xaxis.get_majorticklabels(), rotation=15)
plt.show()
鏈接我試圖跟隨:
任何幫助深表感謝.
總結
以上是生活随笔為你收集整理的python读取csv画图datetime_python – CSV数据(Timestamp和事件)的时间表绘图:x-label常量...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php项目中sql,php – 大括号{
- 下一篇: js 动态创建注释节点 createCo