[P/M/K] simple way to downcast type to reduce memory
<class'pandas.core.frame.DataFrame'> RangeIndex:5 entries,0 to 4 Data columns (total 11 columns): Season_Year 5 non-null int64 GameKey 5 non-null int64 PlayID 5 non-null int64 GSISID 5 non-null float64 Time 5 non-null object x 5 non-null float64 y 5 non-null float64 dis 5 non-null float64 o 5 non-null float64 dir5 non-null float64 Event 0 non-null float64 dtypes: float64(7), int64(3),object(1) memory usage:520.0+bytes
# Find out the smallest data type possible for each numeric feature float_cols = df_temp.select_dtypes(include=['float']) int_cols = df_temp.select_dtypes(include=['int'])for cols in float_cols.columns: df_temp[cols]= pd.to_numeric(df_temp[cols], downcast='float')for cols in int_cols.columns: df_temp[cols]= pd.to_numeric(df_temp[cols], downcast='integer')print(df_temp.info())
<class'pandas.core.frame.DataFrame'> RangeIndex:5 entries,0 to 4 Data columns (total 11 columns): Season_Year 5 non-null int16 GameKey 5 non-null int8 PlayID 5 non-null int16 GSISID 5 non-null float32 Time 5 non-null object x 5 non-null float32 y 5 non-null float32 dis 5 non-null float32 o 5 non-null float32 dir5 non-null float32 Event 0 non-null float32 dtypes: float32(7), int16(2), int8(1),object(1) memory usage:285.0+bytesNone