I have a dataframe with 30 columns. when I load the data with pd.read_csv() method, all the columns' data types by default is set to object.
I want to change col-1 & col-5 to int & rest of the columns to category.
my question is, how can I set the remaining columns to category at once,
I know I can do something cumbersome like below
+------------------------------------------------+
| df['col-1'] = df['col-1'].astype('int) |
+------------------------------------------------+
| df['col-2'] = df['col-2'].astype('category') |
| ... |
| df['col-5'] = df['col-5'].astype('int') |
+------------------------------------------------+
| ... |
| df['col-29'] = df['col-29'].astype('category') |
+------------------------------------------------+
| df['col-30'] = df['col-30'].astype('category') |
+------------------------------------------------+
is there any way I could do something like below while reading the csv
pd.read_csv('myfile.csv', dtype={('col-1','col-5') : int, 'rest' : category})?
is this possible??