0

I tried to plot data in Tkinter window having 12000 rows of excel data. But after removing index for resampling the data i am unable to display matplotlib graph on Tkinter GUI.

dp.index=pd.to_datetime(dp['Test Time']) dp2=dp.resample('5min').mean()

These are the lines I used for resampling data to display matplotlib graph in Tkinter window without overlapping xaxis data.

                   Test Time  Temperature
0      2021/01/22   19:51:19         0.00
1      2021/01/22   19:51:38        25.00
2      2021/01/22   19:51:58        25.03
3      2021/01/22   19:52:18        25.03
4      2021/01/22   19:52:38        24.98
...                      ...          ...
12252  2021/01/25   15:55:18         3.08
12253  2021/01/25   15:55:38         2.44
12254  2021/01/25   15:55:58         1.70
12255  2021/01/25   15:56:18         0.91
12256  2021/01/25   15:56:38         0.65

[12257 rows x 2 columns]


`dp = pd.read_excel('demo11.xlsx')
dp.index=pd.to_datetime(dp['Test Time'])
dp.drop(columns=['Test Time'],inplace=True)
dp2=dp.resample('5min').mean() 


root = tk.Tk()
figure3 = plt.Figure(figsize=(5, 4), dpi=100)
ax3 = figure3.add_subplot(111)
ax3.scatter(dp2['Test Time'], dp2['Temperature'], color='g')
scatter3 = FigureCanvasTkAgg(figure3, root)
scatter3.get_tk_widget().pack(side=tk.LEFT, fill=tk.BOTH)
ax3.legend(['Temperature'])
ax3.set_xlabel('Test Time')
ax3.set_title('Test Time Vs. Temperature')
root.mainloop()`

I am getting following error

The above exception was the direct cause of the following exception:
KeyError: 'Test Time'
Capybara
  • 453
  • 1
  • 4
  • 13
saran
  • 1
  • 2
  • The line `dp.drop(columns=['Test Time'],inplace=True)` removes the "Test time" column from the data frame, so `dp2` won't contain a "Test Time" column. This is what causes the error on you line `ax3.scatter(dp2['Test Time'], dp2['Temperature'], color='g')`. – Matt Pitkin Dec 08 '22 at 11:26
  • Maybe doing `ax3.scatter(dp2.index, dp2['Temperature'], color='g')` will achieve what you want – Matt Pitkin Dec 08 '22 at 11:28

0 Answers0