I have a pandas framework with a "cap" column. This column mainly consists of floats, but has several rows in it, for example, at index 2.
df = cap 0 5.2 1 na 2 2.2 3 7.6 4 7.5 5 3.0 ...
I import my data from the csv file as follows:
df = DataFrame(pd.read_csv(myfile.file))
Unfortunately, when I do this, the "cap" column is imported entirely as rows. I would like the floats to be identified as float and strings as strings. Trying to convert this with:
df['cap'] = df['cap'].astype(float)
causes an error:
could not convert string to float: na
Is there a way to make all numbers in floats, but save "na" as a string?
python pandas dataframe
natsuki_1996 Nov 08 '13 at 4:31
source share