Specify dtype when Reading pandas DataFrame from CSV in Python (Example) | Set Data Type of Columns

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

import pandas as pd # Import pandas library

data = pd.DataFrame({'x1':range(11, 17), # Create pandas DataFrame
'x2':['x', 'y', 'z', 'z', 'y', 'x'],
'x3':range(17, 11, - 1),
'x4':['a', 'b', 'c', 'd', 'e', 'f']})
print(data) # Print pandas DataFrame

dtype = {'x1': int, 'x2': str, 'x3': int, 'x4': str})

# x1 int32
# x2 object
# x3 int32
# x4 object
# dtype: object

Follow me on Social Media:

Рекомендации по теме
welcome to shbcf.ru