Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'DataFrame' object has no attribute 'r' #9

Closed
TranNgocKhoa opened this issue Oct 10, 2021 · 2 comments
Closed

'DataFrame' object has no attribute 'r' #9

TranNgocKhoa opened this issue Oct 10, 2021 · 2 comments

Comments

@TranNgocKhoa
Copy link

Hello,
I'm trying to run file 01_machine_learning_workflow. But when execute this code:

correl = (X
          .apply(lambda x: spearmanr(x, y))
          .apply(pd.Series, index=['r', 'pval']))

correl.r.sort_values().plot.barh();

I got this error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
/var/folders/lm/wvh4bt6d1jxfppzrzx123szh0000gp/T/ipykernel_7138/2418974112.py in <module>
      3           .apply(pd.Series, index=['r', 'pval']))
      4 
----> 5 correl.r.sort_values().plot.barh();

~/opt/anaconda3/envs/quant/lib/python3.8/site-packages/pandas/core/generic.py in __getattr__(self, name)
   5485         ):
   5486             return self[name]
-> 5487         return object.__getattribute__(self, name)
   5488 
   5489     def __setattr__(self, name: str, value) -> None:

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

How can I resolve this issue and where is r and pval from?

Thanks for advance!

@TranNgocKhoa
Copy link
Author

The dataframe should be transpose first:

correl = (X
          .apply(lambda x: spearmanr(x, y))
          .apply(pd.Series)
         ).transpose()

correl = correl.rename(columns={0: "r", 1: "pval"})
correl

@stefan-jansen
Copy link
Collaborator

Please refer to this repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants