I was following the advice here to change the column data type of a pandas dataframe. However, it does not seem to work if I reference the columns by index numbers instead of column names. Is there a way to do this correctly?
In [49]: df.iloc[:, 4:].astype(int)
Out[49]:
<class 'pandas.core.frame.DataFrame'>
Int64Index: 5074 entries, 0 to 5073
Data columns (total 3 columns):
5 5074 non-null values
6 5074 non-null values
7 5074 non-null values
dtypes: int64(3)
In [50]: df.iloc[:, 4:] = df.iloc[:, 4:].astype(int)
In [51]: df
Out[51]:
<class 'pandas.core.frame.DataFrame'>
Int64Index: 5074 entries, 0 to 5073
Data columns (total 7 columns):
1 5074 non-null values
2 5074 non-null values
3 5074 non-null values
4 5074 non-null values
5 5074 non-null values
6 5074 non-null values
7 5074 non-null values
dtypes: object(7)
In [52]: