UChicago-CCA-2021 / Frequently-Asked-Questions

Repository to ask questions - please use the issues page to ask your questions.
0 stars 0 forks source link

AttributeError: 'DataFrame' object has no attribute 'as_matrix' #30

Open Raychanan opened 3 years ago

Raychanan commented 3 years ago

In week 6 jupyter notebook, it reports an error when I'm running the following lines. I was trying to solve the problem by replacing as_matrix with to_numpy. But the relevant discussion mentions that they are slightly different. So can you please tell me how to correct my the sample code? Thanks for your help!

ldaDFV = ldaDF[:10][['topic_%d' %x for x in range(10)]]
ldaDFVisN = ldaDF[:10][['name']]
ldaDFVis = ldaDFV.as_matrix(columns=None)
ldaDFVisNames = ldaDFVisN.as_matrix(columns=None)
ldaDFV

error message

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-71-ce6047e5b0d8> in <module>
      1 ldaDFV = ldaDF[:10][['topic_%d' %x for x in range(10)]]
      2 ldaDFVisN = ldaDF[:10][['name']]
----> 3 ldaDFVis = ldaDFV.as_matrix(columns=None)
      4 ldaDFVisNames = ldaDFVisN.as_matrix(columns=None)
      5 ldaDFV

~/opt/anaconda3/lib/python3.8/site-packages/pandas/core/generic.py in __getattr__(self, name)
   5137             if self._info_axis._can_hold_identifiers_and_holds_name(name):
   5138                 return self[name]
-> 5139             return object.__getattribute__(self, name)
   5140 
   5141     def __setattr__(self, name: str, value) -> None:

AttributeError: 'DataFrame' object has no attribute 'as_matrix'
xxicheng commented 3 years ago

I tried this instead and it worked: ldaDFVis = ldaDFV.values ldaDFVisNames = ldaDFVisN.values

https://stackoverflow.com/questions/62712910/how-to-solve-this-attribution-error-attributeerror-dataframe-object-has-no-at

Raychanan commented 3 years ago

@xxicheng Thank you very much!

bhargavvader commented 3 years ago

Yay, happy to see you helping each other with this :) Cheers @xxicheng !