How to resolve TypeError: 'No Numeric Data to Plot', when numeric data exists in Python

Viewed 3846

I have the following dataframe from which I want to create a line plot for Reputation vs Views, but although both data types for the 2 columns show that they are integers I get an error. Please suggest me how to rectify it.

DataFrame (Original has many more rows and columns)

Id  Reputation  Views   UpVotes DownVotes   AccountId   ProfileImageUrl
-1  1               0   21001   27468             -1    NaN
 1  21228       25360   1052    90             36500    NaN

Code for Line Plot

df_users.plot(kind='line',x='Reputation',y='Views')

Error

> TypeError                                 Traceback (most recent call
> last) <ipython-input-16-bbf2a427a767> in <module>()
> ----> 1 df_users.plot(kind='line',x='Reputation',y='Views')
> 
> 3 frames
> /usr/local/lib/python3.6/dist-packages/pandas/plotting/_matplotlib/core.py
> in _compute_plot_data(self)
>     408         # no non-numeric frames or series allowed
>     409         if is_empty:
> --> 410             raise TypeError("no numeric data to plot")
>     411 
>     412         # GH25587: cast ExtensionArray of pandas (IntegerArray, etc.) to
> 
> TypeError: no numeric data to plot
1 Answers

The following code answered my question:

df_users[['Views', 'Reputation']] = df_users[['Views','Reputation']].apply(pd.to_numeric) 
Related