Python pandas < pandas.core.groupby.DataFrameGroupBy对象位于...> [英] Python Pandas <pandas.core.groupby.DataFrameGroupBy object at ...>
本文介绍了Python pandas < pandas.core.groupby.DataFrameGroupBy对象位于...>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试对行中的相同信息进行分组和计数:
I am trying to group and count the same info in a row:
#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 时,会引发错误
我尝试搜索相同的错误,但找不到有效的答案来帮助解决问题.
I have tried searching this same error but I have not found a valid answer to help me fix my problem.
推荐答案
看看有关分组依据
使用映射器的组序列(字典或键函数,应用给定的函数 分组,返回结果为系列)或按一系列列
Group series using mapper (dict or key function, apply given function to group, return result as series) or by a series of columns
上一个内容摘录自此处
这是一个简单的例子:
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
<pandas.core.groupby.DataFrameGroupBy object at 0x00000000097EEB38>
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
您明白了,可以使用我提供的第一个链接从此处进行构建.
You get the idea, you can build from here using the first link I provided.
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
这篇关于Python pandas < pandas.core.groupby.DataFrameGroupBy对象位于...>的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文