python 熊猫,Python熊猫

我试图连续分组和计算相同的信息:

#Functions

def postal_saude ():

global df, lista_solic

#List of solicitantes in Postal Saude

list_sol = [lista_solic["name1"], lista_solic["name2"]]

#filter Postal Saude Solicitantes

df = df[(df['Cliente']==lista_clientes["6"])

& (df['Nome do solicitante'].isin(list_sol))]

#Alphabetical order

df = df.sort_index(by=['Nome do solicitante', 'nomeCorrespondente'])

#Grouping data of column

grouping = df.groupby('Tipo do serviços');

print (grouping)

postal_saude()

当它到达df.groupby时会产生错误

我试过搜索同样的错误,但我没有找到一个有效的答案,以帮助我解决我的问题.

请帮忙

请查看有关

Group By的此文档

Group series using mapper (dict or key function, apply given function

to group, return result as series) or by a series of columns

上一个是从here开始的

这是一个简单的例子:

df = pd.DataFrame({'a':[1,1,1,2,2,2,3,3,3,3],'b':np.random.randn(10)})

df

a b

0 1 1.048099

1 1 -0.830804

2 1 1.007282

3 2 -0.470914

4 2 1.948448

5 2 -0.144317

6 3 -0.645503

7 3 -1.694219

8 3 0.375280

9 3 -0.065624

groups = df.groupby('a')

groups # Tells you what "df.groupby('a')" is, not an error

groups.count() # count the number of 1 present in the 'a' column

b

a

1 3

2 3

3 4

groups.sum() # sums the 'b' column values based on 'a' grouping

b

a

1 1.224577

2 1.333217

3 -2.030066

你明白了,你可以使用我提供的第一个链接从这里构建.

df_count = groups.count()

df_count

b

a

1 3

2 3

3 4

type(df_count) # assigning the `.count()` output to a variable create a new df

pandas.core.frame.DataFrame

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值