[P/M/K] simple way to downcast type to reduce memory

匿名 (未验证) 提交于 2019-12-02 23:03:14
<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 dir            5 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 dir            5 non-null float32 Event          0 non-null float32 dtypes: float32(7), int16(2), int8(1), object(1) memory usage: 285.0+ bytes None 
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!