“Lire Pickle File Python” Réponses codées

Pickle un dictionnaire

import pickle #credits to stack overflow user= blender

a = {'hello': 'world'}

with open('filename.pkl', 'wb') as handle:
    pickle.dump(a, handle, protocol=pickle.HIGHEST_PROTOCOL)

with open('filename.pkl', 'rb') as handle:
    b = pickle.load(handle)

print (a == b)
Shiny Snail

Lire le fichier de cornichon

with open('filename', 'rb') as f:
    x = pickle.load(f)
Wrong Wallaby

Créer un fichier Pickle Python

import pickle
file_name='my_file.pkl'
f = open(file_name,'wb')
pickle.dump(my_data,f)
f.close()
Tremendous Enceladus

Lire Pickle File Python

data = pd.read_pickle('dtm.pkl')
Distinct Dragonfly

fichier de cornichon ouvert Python

'''3 ways to open file with python (e.g: 'my_pickle_file.pkl)':'''

# ORIGINAL
with open('my_pickle_file.pickle', 'rb') as f :
    pickle_file = pickle.load(f)

# QUICK
pickle_file =  pickle.load(open("my_pickle_file.pickle", 'rb'))

# PANDAS
pickle_file = pd.read_pickle('my_pickle_file.pickle')
Tirbo06

Lire Pickle File Python

import pandas as pd
#the object type is the one defined in the pickle, it is not a dataframe
object = pd.read_pickle(r'filepath')
Yesid Cano Castro

Réponses similaires à “Lire Pickle File Python”

Questions similaires à “Lire Pickle File Python”

Plus de réponses similaires à “Lire Pickle File Python” dans Python

Parcourir les réponses de code populaires par langue

Parcourir d'autres langages de code