Convert Float to String in pandas DataFrame Column in Python (4 Examples) | Using astype() & apply()

preview_player
Показать описание
Python code of this video:

import pandas as pd # Load pandas

data = pd.DataFrame({'x1':[1.1, 2.2, 3.3, 4.4, 5.5], # Create pandas DataFrame
'x2':[1.5, 2.5, 3.5, 4.5, 5.5],
'x3':[0.1, 0.2, 0.3, 0.4, 0.5]})
print(data) # Print pandas DataFrame

# x1 float64
# x2 float64
# x3 float64
# dtype: object

data_new1['x1'] = data_new1['x1'].astype(str) # Transform float to string

# x1 object
# x2 float64
# x3 float64
# dtype: object

# x1 float64
# x2 object
# x3 object
# dtype: object

# x1 object
# x2 object
# x3 object
# dtype: object

data_new4['x1'] = data_new4['x1'].apply(str) # Transform string to float

# x1 object
# x2 float64
# x3 float64
# dtype: object

Follow me on Social Media:

Рекомендации по теме
Комментарии
Автор

Ive duration time column used the code didn't worked can u pls help

Maryj
Автор

The title of this content and what was actually done are completely different from each other.

netebom