← retour aux snippets

pandas: to_feather (feather rapide)

Sauvegarder en feather (Apache Arrow) très rapide.

objectif

Sauvegarder en feather (Apache Arrow) très rapide.

code minimal

import pandas as pd
df = pd.DataFrame({"a":[1,2], "b":["x","y"]})
_ = df.to_feather("data.feather")
print("ok")

utilisation

import pandas as pd
df = pd.read_feather("data.feather")
print(df.to_dict(orient="list"))

variante(s) utile(s)

import pandas as pd
df = pd.DataFrame({"a":[1,2]})
# feather n'enregistre pas l'index; inclure colonne id si besoin
df.reset_index().to_feather("with_index.feather")
print("ok")

notes

  • Idéal pour échanges rapides entre pandas/Arrow.