【发布时间】:2018-03-16 06:46:46
【问题描述】:
我有一个 Excel,它有 10 秒的频繁数据和时间戳,因为我希望那里有 10 秒的频率数据应该显示为 On(1),而频率时间戳不匹配的地方应该显示为 OFF(0 ) 和情节一样。
样本数据:
timestamp
1/6/2017 0:00:10
1/6/2017 0:00:20
1/6/2017 0:00:40
1/6/2017 0:00:50
1/6/2017 0:01:00
所以,
timestamp
1/6/2017 0:00:39 timestamp is there ON
1/6/2017 0:00:49 timestamp is not there Off
1/6/2017 0:00:59 timestamp is there ON
1/6/2017 0:01:09 timestamp is not there Off
1/6/2017 0:01:19 timestamp is there ON
1/6/2017 0:01:29 timestamp is there ON
1/6/2017 0:01:39 timestamp is there ON
代码:下面是我的代码;在此我想绘制一个图表。
import matplotlib.pyplot as plt
import pandas as pd
import matplotlib
matplotlib.style.use('ggplot')
#reading CSv
df = pd.read_csv('test.csv', parse_dates=['timestamp'])
print (df)
#set Index
df['timestamp'] = pd.to_datetime(df['timestamp'])
df = df.set_index('timestamp')
print (df)
#reindexing
df.reindex(pd.date_range(start=df.index[0], end=df.index[-1], freq='30s'))
这个 On Off 应该出现在情节中,例如 On 表示向上,Off 表示向下。
提前谢谢。我是新来的,请帮忙。
【问题讨论】:
-
什么时候需要帮助?问题出在哪里?你还试过什么?请参阅How to Ask 和edit 相应的问题。
-
抱歉以错误的方式写问题。请检查更新
标签: python matplotlib timestamp