Home > Software engineering >  Is there a function to download a pickle file via requests.post(url) and load it into a dataframe wi
Is there a function to download a pickle file via requests.post(url) and load it into a dataframe wi

Time:06-02

I am trying to download a pickle file from a web-based API via the requests.post(url) function in python. I was able to download and load the pickle file in a dataframe however i had to save it locally before loading it. I wanted to check if there is a way to load the pickle file directly into the dataframe without having to save it locally. I was able to do it for csv files (as seen below) however not for pickle files:

r=requests.post(url)
data=r.content.decode()
df=pd.read_csv(io.StringIO(data),header=0,engine=None)

Any help is appreciated, thanks.

CodePudding user response:

Just a guess at something that might work for you since it looks like the pickle file contains text-csv-like data.

df=pd.read_csv(io.StringIO(pd.read_pickle(url)),header=0,engine=None)

CodePudding user response:

thanks for your suggestion. Basically i ended up using the following and it worked;

r=requests.post(url)
data=r.content
df=pd.read_pickle(io.BytesIO(data))
  • Related