python、pandas、按组自动相关

2024-05-15 13:17:15 发布

您现在位置:Python中文网/ 问答频道 /正文

       fips  year        sc 
0       1001  1990 -0.707465
1       1001  1991 -0.707465
2       1001  1992 -0.707465
3       1001  1993 -0.707465
4       1001  1994 -0.707465
5       1001  1995 -0.707465
6       1002  1996 -0.707465
7       1002  1997 -0.607672
8       1002  1998 -0.607672
9       1002  1999 -0.607672
10      1002  2000 -0.607672
11      1002  2001 -0.607672
12      1002  2002 -0.607672 

我想用一组fip来计算sc变量的自相关。我试过密码:

test=sc_itpl.groupby('fips')['sc'].autocorr(lag=1)

我得到一个错误:

AttributeError: Cannot access callable attribute 'autocorr' of 'SeriesGroupBy' objects, try using the 'apply' method

谢谢


Tags: test密码access错误yearlagattributeerrorsc