AttributeError:' SeriesGroupby'对象没有属性' tolist'
在熊猫的数据框架中:我要计算stroke
coulmn中有多少个值1
,对于Residence_type
列中的每个值。为了计算多少1
,我认为stroke
列将其转换为列表,我认为更容易。
因此,例如,中的值
在 Residence_type
stroke> Stroke
column中具有300次1
。 。
数据是这样的:
Residence_type Stroke
0 Rural 1
1 Urban 1
2 Urban 0
3 Rural 1
4 Rural 0
5 Urban 0
6 Urban 0
7 Urban 1
8 Rural 0
9 Rural 1
代码:
grpby_variable = data.groupby('stroke')
grpby_variable['Residence_type'].tolist().count(1)
最终目标是在 1 出现的次数之间找到差异,对于中的每个值Residence_Type 列(农村或城市)。
我在做对吗?这是什么错误?
In a Panda's dataframe: I want to count how many of value 1
there is, in the stroke
coulmn, for each value in the Residence_type
column. In order to count how much 1
there is, I convert the stroke
column to a list, easier I think.
So for example, the value Rural
in Residence_type
has 300 times 1
in the stroke
column.. and so on.
The data is something like this:
Residence_type Stroke
0 Rural 1
1 Urban 1
2 Urban 0
3 Rural 1
4 Rural 0
5 Urban 0
6 Urban 0
7 Urban 1
8 Rural 0
9 Rural 1
The code:
grpby_variable = data.groupby('stroke')
grpby_variable['Residence_type'].tolist().count(1)
the final goal is to find the difference between the number of times the value 1
appears, for each value in the Residence_type column (rural or urban).
Am I doing it right? what is this error ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不确定我需要做什么。请尝试过滤器proke == 1,groupby and count;
如果您需要类别之间的差异,可以尝试以下操作
Not sure I got what you need done. Please try filter stroke==1, groupby and count;
You could try the following if you need the differences between categories
假设
stroke
仅包含1或0,则可以做:Assuming that
Stroke
only contains 1 or 0, you can do: