Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to convert data with float, int and strings to just strings and float

I have a csv with data in different formats. there are float, int and strings.

How can I modify just the int into float?

I have not tried much, just with this:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

df=df.astype(dtype=np.float64, copy=True, errors='raise')

but cant manage to make it work, because there are also strings

How can I solve this?

>Solution :

The columns of a pandas DataFrame (or a Series) are homogeneously of type. You can inspect this with dtype (or DataFrame.dtypes)

You can select_dtypes first and and finally convert to float using df.astype

tmp = df.select_dtypes(include=['Int64'])
df[tmp.columns]= tmp.astype('float64')
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading