Home > Software design >  'DataFrame' object has no attribute 'DataFrame'
'DataFrame' object has no attribute 'DataFrame'

Time:11-03

I am trying to turn a variable into a pandas DataFrame. The following is my code:

pk = pd.DataFrame()

This is what I am wanting to use the DataFrame for: pk['product_id'], pk['UOM'] = [ss_uom.product_id, ss_uom.UOM]

This is the error I am experiencing directly after declaring pk as a DataFrame:

AttributeError                            Traceback (most recent call last)
<ipython-input-58-2dd2e5d04c54> in <module>()
----> 1 pK = pd.DataFrame()

/usr/local/lib/python3.7/dist-packages/pandas/core/generic.py in __getattr__(self, name)
   5139             if self._info_axis._can_hold_identifiers_and_holds_name(name):
   5140                 return self[name]
-> 5141             return object.__getattribute__(self, name)
   5142 
   5143     def __setattr__(self, name: str, value) -> None:

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

I'm not sure what the problem is specifically with this variable as I have declared about half a dozen similar variables as DataFrames directly above this variable in a Google Colab notebook, with the exact same process and all have passed successfully.

Any input would be greatly appreciated. Thank you in advance!

CodePudding user response:

Are you sure that pd itself is not a DataFrame? you can check it with the type function:

type(pd)

It must return 'module'. Otherwise, you should check your code for the wrong assigning of pd variable.

  • Related