Pandas category dtype: Reduce string column memory by 90%

Pandas category dtype: Reduce string column memory by 90%

Does your Python Pandas column contain repeated strings? Turn it into a ‘category’ series (like an enum) to save memory:

df['c'].memory_usage()   # 124,957,472
df['c'] = (df['c'].astype('category'))
df['c'].memory_usage() 12,496,555

That’s right — 90% less memory!