Reputation: 1
I tried to go take average of this column but could not. can anybody help me?
Upvotes: 0
Views: 40
Reputation: 2493
You can check the column values type using dtypes
Here is an example DataFrame
and how to get the column values type
Data = {'Products': ['AAA','BBB','CCC','DDD','EEE'],
'Prices': ['200','700','400','1200','900']}
df = pd.DataFrame(Data)
print (df['Products'].dtypes)
print (df['Price'].dtypes)
Here you can see that the values in the column Price are int64
Now if I add a new row with a string value the column values type will be different object
df.loc[len(df)] = ["Some product", "222"]
print (df['Price'].dtypes)
Which means in your case that you have some inconsistency in data values types in the column you are using. You need to find the rows causing that and see if you can fix pre-process them by for example simply enforcing the column values type to be numeric
.
df['Prices'] = df['Prices'].astype(int)
print (df['Prices'].dtypes)
Upvotes: 0
Reputation: 199
You need to check if the data type for your column is numeric or not.
For average function, you need to have numeric data, should not be the string.
Upvotes: 1