“Leia o arquivo de pickle python” Respostas de código

Pecar um dicionário

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

Leia o arquivo em pickle

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

Crie Python Python

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

Leia o arquivo de pickle python

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

Arquivo de picles aberto 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

Leia o arquivo de pickle 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

Respostas semelhantes a “Leia o arquivo de pickle python”

Perguntas semelhantes a “Leia o arquivo de pickle python”

Mais respostas relacionadas para “Leia o arquivo de pickle python” em Python

Procure respostas de código populares por idioma

Procurar outros idiomas de código