What is the difference between save a pandas dataframe to pickle and to csv?

csv

  • ✅human readable
  • ✅cross platform
  • ⛔slower
  • ⛔more disk space
  • ⛔doesn't preserve types in some cases

pickle

  • ✅fast saving/loading
  • ✅less disk space
  • ⛔non human readable
  • ⛔python only

Also take a look at parquet format (to_parquet, read_parquet)

  • ✅fast saving/loading
  • ✅less disk space than pickle
  • ✅supported by many platforms
  • ⛔non human readable

Pickle is a serialized way of storing a Pandas dataframe. Basically, you are writing down the exact representation of the dataframe to disk. This means the types of the columns are and the indices are the same. If you simply save a file as csv, you are just storing it as a comma separated list. Depending on your data set, some information will be lost when you load it back up.

You can read more about pickle library in python, here.