我试图绘制一个数据帧,但我遇到了一些我不知道如何解决的错误。
Python代码:
import numpy as np
from datetime import date,time,datetime
import pandas as pd
import csv
df = pd.read_csv('MainD2.csv', parse_dates=['Time_Stamp'], infer_datetime_format=True)
df["Time_Stamp"] = pd.to_datetime(df["Time_Stamp"]) # convert to Datetime
df_filter = df[df["Curr"].le(3.0)] # new df with less or equal to 0.5
#print(df_filter)
where = (df_filter[df_filter["Time_Stamp"].diff().dt.total_seconds() > 1] ["Time_Stamp"] - pd.Timedelta("1s")).astype(str).tolist() # Find where diff > 1 second
df_filter2 = df[df["Time_Stamp"].isin(where)] # Create new df with those
#print(df_filter2)
df_filter2["AC_Input_Current"] = 0.0 # Set c1 to 0.0
#df_filter2
df = df.set_index("Time_Stamp")
df_filter2 = df_filter2.set_index("Time_Stamp")
df.loc[df_filter2.index] = df_filter2
def getMask(start,end):
mask = (df['Time_Stamp'] > start) & (df['Time_Stamp'] <= end)
return mask;
start = '2017-06-26 01:05:00'
end = '2017-06-26 01:20:00'
timerange = df.loc[getMask(start, end)]
timerange.plot(x='Time_Stamp', y='AC_Input_Current', style='-', color='black')*
* ------------------ 绘图部分-------------------
timerange.plot(x='Time_Stamp', y='AC_Input_Current', style='-', color='black')
我在尝试绘图时遇到了这个错误:
KeyError: 'Time_Stamp'