Python Pandas TypeError: Empty ‘DataFrame’: no numeric data to plot

Tushare returns the dataframe format of panda, but an error occurs when executing the following code: typeerror: empty ‘dataframe’: no numeric data to plot

import tushare as ts

df_all = ts.realtime_boxoffice()
df_box_office = df['BoxOffice']
df_box_office.index = df['Irank']
df_box_office.plot(kind='bar')

Repeatedly output DF [‘boxoffice ‘] to confirm that it has value. I can’t figure out why it will report “empty”, and Baidu has no result

I thought there was a bug in the combination of tusahre and pandas. When I was ready to give up, I saw “numeric” in the error report. Does it mean that DF [‘boxoffice ‘] is a string type, not a numeric type, which leads to the error report

See the usage of “astype ()” in the official documents of panda, and change the code to the following successful drawing (in addition, use “ PD. To_ Numeric () “is OK, but I have to go back to panda from tushare. I feel that the code doesn’t look so smooth

import tushare as ts

df_all = ts.realtime_boxoffice()
df_box_office = df['BoxOffice'].astype(float)
df_box_office.index = df['Irank']
df_box_office.plot(kind='bar')

Similar Posts: