filmov
tv
Convert String to Integer in pandas DataFrame Column in Python (Examples) | astype() & to_numeric()

Показать описание
Python code of this video:
import pandas as pd # Import pandas
data = pd.DataFrame({'x1':['1', '7', '5', '4', '7', '5'], # Create pandas DataFrame
'x2':['10', '2', '9', '15', '22', '5'],
'x3':['3', '4', '5', '8', '1', '6']})
print(data) # Print pandas DataFrame
# x1 object
# x2 object
# x3 object
# dtype: object
data_new1['x1'] = data_new1['x1'].astype(int) # Transform string to integer
# x1 int32
# x2 object
# x3 object
# dtype: object
# x1 object
# x2 int32
# x3 int32
# dtype: object
# x1 int32
# x2 int32
# x3 int32
# dtype: object
# x1 int64
# x2 object
# x3 object
# dtype: object
Follow me on Social Media:
import pandas as pd # Import pandas
data = pd.DataFrame({'x1':['1', '7', '5', '4', '7', '5'], # Create pandas DataFrame
'x2':['10', '2', '9', '15', '22', '5'],
'x3':['3', '4', '5', '8', '1', '6']})
print(data) # Print pandas DataFrame
# x1 object
# x2 object
# x3 object
# dtype: object
data_new1['x1'] = data_new1['x1'].astype(int) # Transform string to integer
# x1 int32
# x2 object
# x3 object
# dtype: object
# x1 object
# x2 int32
# x3 int32
# dtype: object
# x1 int32
# x2 int32
# x3 int32
# dtype: object
# x1 int64
# x2 object
# x3 object
# dtype: object
Follow me on Social Media:
Комментарии