如何使用 std 输入函数对数据进行切片?
我的数据如下:
time duration
0 2018-07-04 12:19:29+00:00 4000000000
1 2018-07-04 12:20:30+00:00 4000000000
2 2018-07-04 12:21:31+00:00 3700000000
3 2018-07-04 12:22:31+00:00 4100000000
4 2018-07-04 12:23:31+00:00 4100000000
我从 influxdb 查询数据,然后转换为 Dataframe。SyntaxError: invalid token
输入时给我一个错误Starting date :
我试图将time
列拆分为单独date
的Time
import influxdb
import pandas as pd
from datetime import datetime
import matplotlib.pyplot as plt
client = influxdb.DataFrameClient('192.168.1.108' , port = 8086, database = 'Mlogi_01081081')
dfs_dict = client.query('select * from sy_1')
measurement = next(iter(dfs_dict))
ret = dfs_dict[measurement]
df = pd.DataFrame.from_dict(ret)
df = df.reset_index()
df.rename( columns={'index':'time'}, inplace=True )
df['time'] = pd.to_datetime(df['time'])
df['Time'] = df['time'].dt.time
df['date'] = df['time'].dt.date
df['date'] = pd.to_datetime(df['date'])
df = df.set_index(['date'])
a = input('Starting_Date: ')
b = input('Ending_Date :')
starting_date = datetime.strptime(a, "%Y-%m-%d").date()
ending_date = datetime.strptime(b, "%Y-%m-%d").date()
df.loc[starting_date:ending_date]
还是没有运气!!!