python读取csv画图datetime_python – CSV数据(Timestamp和事件)的时间表绘图:x-label常量...
(這個(gè)問(wèn)題可以單獨(dú)閱讀,但是是續(xù)集:
Timeseries from CSV data (Timestamp and events))
我想通過(guò)使用python的熊貓模塊(見(jiàn)下面的鏈接)的時(shí)間表表示,可視化CSV數(shù)據(jù)(從2個(gè)文件),如下所示.
df1的樣本數(shù)據(jù):
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,我試圖顯示數(shù)據(jù)集中每一天的事件總和.
第二個(gè)數(shù)據(jù)集df0具有相似的結(jié)構(gòu),但只包含零:
df0的樣本數(shù)據(jù):
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軸標(biāo)簽只顯示相同的日期,我的問(wèn)題是:如何顯示不同的日期? (什么導(dǎo)致在x標(biāo)簽上多次顯示相同的日期?)
腳本到目前為止
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()
鏈接我試圖跟隨:
任何幫助深表感謝.
總結(jié)
以上是生活随笔為你收集整理的python读取csv画图datetime_python – CSV数据(Timestamp和事件)的时间表绘图:x-label常量...的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: php项目中sql,php – 大括号{
- 下一篇: js 动态创建注释节点 createCo