Polars版本: importpolarsasplimportnumpyasnpdefreduce_mem_usage_pl(df):""" iterate through all the columns of a dataframe and modify the data typeto reduce memory usage in a Polars DataFrame."""start_mem=df.estimated_size("mb")print('Memory usage of dataframe is{:.2f}MB'.format(start_m...
def reduce_mem_usage(df):"""iterate through all the columns of a dataframe and modify the data typeto reduce memory usage."""start_mem =df.memory_usage().sum() print('Memory usage of dataframe is {:.2f} MB'.format(start_mem))forcolindf.columns: col_type=df[col].dtypeifcol_type ...
benchmark old ns/op new ns/op delta BenchmarkSchema-16 569319394 238469401 -58.11% benchmark old allocs new allocs delta BenchmarkSchema-16 1327927 1174085 -11.59% benchmark old bytes new bytes delta BenchmarkSchema-16 293956792 186829161 -36.44% schemahcl: reduce eval mem usage … 8ec9...