Pandas: cannot plot combined csv data from file

45 views
Skip to first unread message

Yushan Zhang

unread,
Jul 31, 2017, 9:08:41 AM7/31/17
to PyData

I use Pandas to process data attached(sage.tar) on Ubuntu 16.04 (download the attached file, tar it and just copy and paste the following code):

import pandas as pd
import numpy as np
import glob


# combine time for one set
def draw_comb_time(path):
 draw_time
(cat_data(path))


# combine data together
def cat_data(path):
 csv
= glob.glob(path + '/*.csv')
 csv_all
= [pd.read_csv(f) for f in csv]
 df
= [pd.DataFrame(d) for d in csv_all]
 data
= pd.concat(df)
 
return data


def draw_time(data):
 df
= pd.DataFrame(data)
 cumsum
= []
 ticks
= [i for i in np.linspace(0, 10000, 51)]
 
for i in ticks:
 cumsum
.append(df.iloc[:int(i)].sum())
 d
= pd.DataFrame(cumsum)
 d
.plot


draw_comb_time
('sage')


It gives me the error:
/usr/bin/python3.5 /home/zhangysh1995/work/results/scripts/tests.py
Traceback (most recent call last):
File "/home/zhangysh1995/work/results/scripts/tests.py", line 28, in <module>
draw_comb_time('../Out/sage')
File "/home/zhangysh1995/work/results/scripts/tests.py", line 6, in draw_comb_time
draw_time(cat_data(path))
File "/home/zhangysh1995/work/results/scripts/tests.py", line 25, in draw_time
d.plot()
File "/usr/local/lib/python3.5/dist-packages/pandas/plotting/_core.py", line 2627, in __call__
sort_columns=sort_columns, **kwds)
File "/usr/local/lib/python3.5/dist-packages/pandas/plotting/_core.py", line 1869, in plot_frame
**kwds)
File "/usr/local/lib/python3.5/dist-packages/pandas/plotting/_core.py", line 1694, in _plot
plot_obj.generate()
File "/usr/local/lib/python3.5/dist-packages/pandas/plotting/_core.py", line 243, in generate
self._compute_plot_data()
File "/usr/local/lib/python3.5/dist-packages/pandas/plotting/_core.py", line 352, in _compute_plot_data
'plot'.format(numeric_data.__class__.__name__))
TypeError: Empty 'DataFrame': no numeric data to plot
Process finished with exit code 1
I know this error is about type conversion, but I cannot find any data in my file that is not a number. The contents in csv files are output of other scripts, however the above code works well on other data set except the attached. Could anyone help me with this problem?

I appreciate any help.


Thanks,
Yushan
sage.tar

Paul Hobson

unread,
Jul 31, 2017, 12:46:59 PM7/31/17
to pyd...@googlegroups.com
You're not calling the plot method

d.plot  # just the method

Should be:

d.plot()  # calling the method

--
You received this message because you are subscribed to the Google Groups "PyData" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pydata+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Goyo

unread,
Aug 2, 2017, 3:28:05 AM8/2/17
to PyData

El lunes, 31 de julio de 2017, 15:08:41 (UTC+2), Yushan Zhang escribió:

I use Pandas to process data attached(sage.tar) on Ubuntu 16.04 (download the attached file, tar it and just copy and paste the following code):

It is better if you do this yourself too to make sure we run the same code as you. The code you posted does not match the traceback. After fixing an indentation error and make an actual call to d.plot it seems to be working for me.

Regards
Goyo
 
Reply all
Reply to author
Forward
0 new messages