I have downloaded the file mentioned in book "Python for Data Analysis" and was going through the example FEC database mentioned in page 278. I get the following Type error when I ran the command. My versions: Python 3.4; Pandas: 0.14.0. OS: Windows 8
>>> fec=pd.read_csv('c:\python\P00000001-ALL.csv')
>>> (fec.contb_receipt_amt > 0).value_counts()
>>> TypeError: unorderable types: str() > int()
But it is not just this dataset. Any dataset that I am working with have similar problem. Int(Number) data types are being imported as objects like anything else and when run any comparison with numbers(>0) on them I get the above error. What is the work around? I tried importing with dtype option, which throws an error that says int64 or Float64 is not available. I am sure there is a right way of doing. How to load the data frame with the right data types.
Any help is appreciated.
Use pandas DataFrame. astype() function to convert a column from int to string, you can apply this on a specific column or on an entire DataFrame.
A DataFrame is a 2-dimensional data structure that can store data of different types (including characters, integers, floating point values, categorical data and more) in columns.
I got this error for some not identical dates. I solved it using a type change first.
Try :
fec[[contb_receipt_amt]] = fec[[contb_receipt_amt]].astype(str)
Then try again the count.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With