python - Convert only float columns in a pandas dataframe to string -


i have pandas dataframe follows.

   sugar  salt  oil  protein 0    0.0   0.2  0.8      0.0 1    0.7   0.2  0.1      0.0 2    0.0   0.0  1.0      0.9 

i want change floats in dataframe strings, without using column headings below (since have 1000+ columns in original data , vary quite often).

total_rows['columnid'] = total_rows['columnid'].astype(str) 

is there easy way of doing it?

using df.blocks

c = df.blocks['float64'].columns df[c] = df[c].astype(str)  df.dtypes sugar      object salt       object oil        object protein    object dtype: object 

note: df.blocks deprecated v0.21, use df.select_dtypes, this answer shows instead. here's version without loop:

c = df.select_dtypes(include=[object]).columns df[c] = df[c].astype(str) 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -