How to set the data type for columns in a CSV file in the Python programming language. More details: [ Ссылка ]
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
data.to_csv('data.csv', index = False) # Export pandas DataFrame to CSV
data_import = pd.read_csv('data.csv', # Import CSV file
dtype = {'x1': int, 'x2': str, 'x3': int, 'x4': str})
print(data_import.dtypes) # Check column classes of imported data
# x1 int32
# x2 object
# x3 int32
# x4 object
# dtype: object
Follow me on Social Media:
Facebook – Statistics Globe Page: [ Ссылка ]
Facebook – R Programming Group for Discussions & Questions: [ Ссылка ]
Facebook – Python Programming Group for Discussions & Questions: [ Ссылка ]
LinkedIn – Statistics Globe Page: [ Ссылка ]
LinkedIn – R Programming Group for Discussions & Questions: [ Ссылка ]
LinkedIn – Python Programming Group for Discussions & Questions: [ Ссылка ]
Twitter: [ Ссылка ]
Music by bensound.com
![](https://i.ytimg.com/vi/DmHY_zaZupA/maxresdefault.jpg)