CSVファイルに格納されたデータフレームをプロットしたいのですが、以下のようなエラーが出てしまいます。
x軸にindex、y軸にch0とch2をプロットしたいです。いろいろ調べては見たのですが、pandasのプロットがよくわかりませんでした。。。
Traceback (most recent call last):
File "/home/pi/5\17.py", line 14, in <module>
main()
File "/home/pi/5\17.py", line 7, in main
data.plot()
File "/usr/lib/python3/dist-packages/pandas/tools/plotting.py", line
2165, in plot_frame
plot_obj.generate()
File "/usr/lib/python3/dist-packages/pandas/tools/plotting.py", line
900, in generate
self._compute_plot_data()
File "/usr/lib/python3/dist-packages/pandas/tools/plotting.py", line
970, in _compute_plot_data
'plot'.format(numeric_data.class.name))
TypeError: Empty 'DataFrame': no numeric data to plot
python
1コード 2import csv 3import matplotlib as plt 4import pandas as pd 5 6def main(): 7 data = pd.read_csv('myakuha.csv',index_col=0) 8 data.plot() 9 print(data) 10 plot.show() 11 12 13 14if __name__=='__main__': 15 main() 16
このようなデータフレームが格納されてます。(値が0なのは気にしないでください)
ch0 ch2
0 [0] [0]
1 [0] [0]
2 [0] [0]
3 [0] [0]
4 [0] [0]
5 [0] [0]
6 [0] [0]
7 [0] [0]
8 [0] [0]
9 [0] [0]
10 [0] [0]
11 [0] [0]
12 [0] [0]
13 [0] [0]
14 [0] [0]
15 [0] [0]
16 [0] [0]
17 [0] [0]
18 [0] [0]
19 [0] [0]
20 [0] [0]
21 [0] [0]
22 [0] [0]
23 [0] [0]
24 [0] [0]
25 [0] [0]
26 [0] [0]
27 [0] [0]
28 [0] [0]
29 [0] [0]
python
1import pandas as pd 2import time 3import spidev 4import sys 5import numpy as np 6import subprocess 7from threading import Thread 8import csv 9 10 11cond = True 12data1 = 0 13data2 = 0 14df1 = pd.DataFrame(columns=['ch0','ch2'])#data2 15 16 17def main(): 18 spi = spidev.SpiDev() 19 spi.open(0,0) 20 21 def f(): 22 global cond 23 time.sleep(20) 24 cond = False 25 26 thread = Thread(target=f) 27 thread.start() 28 29 while cond: 30 resp = spi.xfer2([0x68,0x00]) 31 data1 = ((resp[0] << 8 ) + resp[1]) & 0x3ff 32 resp2 = spi.xfer([0x78,0x00]) 33 data2 = ((resp2[0] << 8) + resp2[1]) & 0x3ff 34 global df1 35 df1 = df1.append({'ch0':[data1],'ch2':[data2]},ignore_index=True) 36 print (df1) 37 df1.to_csv('myakuha.csv') 38 #left max 39 df10max = df1['ch0'].max() 40 #print('left:',df10max) 41 #right max 42 df12max = df1['ch2'].max() 43 #print('right:',df12max) 44 df110max = np.array(df10max) 45 df112max = np.array(df12max) 46 47 48 if df10max > df12max: 49 leftmax = df110max - df112max 50 print ('overL:',leftmax) 51 52 if df10max < df12max: 53 rightmax = df112max - df110max 54 print ('overR:',rightmax) 55 56 57 58 59 60 61if __name__=='__main__': 62 main() 63
回答2件
あなたの回答
tips
プレビュー