Typeerror: '<' not supported between instances of 'float' and 'str'

Asked

Viewed 1,397 times

0

I need to calculate the median of the variables in a database, but it’s giving error. This error does not occur when using np.Mean in order to calculate the average. The database can be found easily on the Internet. Thanks in advance!

import pandas as pd
import numpy as np

housedata = pd.read_csv("kc_house_data.csv",delimiter=",")

median = pd.DataFrame(np.median(housedata))

1 answer

0

This error means that one of the variables you are passing to calculate the median is as text (even if you can calculate the mean, probably the result is not what you would expect).

With housedata.dtypes if you can test the data type of each column, and if you can convert the column to number using housedata["Nome da Coluna"].astype(float).

Browser other questions tagged

You are not signed in. Login or sign up in order to post.