Exception raised after loading pickle file: 'DataFrame' object has no attribute '_data'

Viewed 1868

I am trying to load a pickle file that contains a dictionary:

import pickle as pk

# load dMAD
dMAD_open = open(r"dMAD.pickle", "rb")
dMAD = pk.load(dMAD_open)
dMAD_open.close()

type(dMAD) # prints correctly: "dict"
dMAD # throws the error message

The loading works without raising an error, but once I try to print dMAD (which should retrun the dictionary) I get this error message:

AttributeError: 'DataFrame' object has no attribute '_data'

I already tried different conda environments with different python installations (python 3.7.7 and 3.8.2). The pickle file and my code are in the same directory. It works on a different computer. It doesn't work on mine, even when I use the same conda environment.

How can I solve this issue? Any help appreciated.

2 Answers

In the end, it worked in an environment running python 3.8.5 and pandas 1.1.3

You might want to catch the exception manually like:

try:
    open(r"dMAD.pickle", "rb")
catch Exception as e:
    print(e) # you will find what is going on here

or even have a deeper look on what is inside this dict with

dir(dMAD)

If you believe it is environment error, go ahead and reinstall it again from the scratch and most probably this is the case. keep on mind if you recently upgraded python version on your local machine that corrupts all old virtual environments if not kept the old version available in the same path.

try to remove the old environment and install a fresh one.

Related