python – pandas DataFrame no numeric data to plot error

python – pandas DataFrame no numeric data to plot error

Try the following before plotting:

df=df.astype(float)

To solve this you have to convert the particular column or columns you want to
use to numeric. First let me create a simple dataframe with pandas and numpy to
understand it better.

#creating the dataframe

import pandas as pd
import numpy as np
details=[[kofi,30,male,1.5],[ama,43,female,2.5]]
pf=pd.DataFrame(np.array(details),[0,1],[name,age,sex,id])

pf  #here i am calling the dataframe

   name age     sex   id
0  kofi  30    male  1.5
1   ama  43  female  2.5

#to make your plot work you need to convert the columns that have numbers into numeric
as seen below 

pf.id=pd.to_numeric(pf.id)
pf.age=pd.to_numeric(pf.age)

pf.plot.scatter(x=id,y=age)

#This should work perfectly

python – pandas DataFrame no numeric data to plot error

Inspired by alex314159, if you have other data than float in the same table

df[YourColumnNameHere]=df[YourColumnNameHere].astype(float)

Leave a Reply

Your email address will not be published.