python dataframe groupby
2016-08-12 16:27
609 查看
使用dataframe实现groupby方法:
输出结果:
# -*- coding: UTF-8 -*- import pandas as pd df = pd.DataFrame([{'col1':'a', 'col2':1, 'col3':'aa'}, {'col1':'b', 'col2':2, 'col3':'bb'}, {'col1':'c', 'col2':3, 'col3':'cc'}, {'col1':'a', 'col2':44, 'col3':'aa'}]) print df.groupby(by='col1').agg({'col2':sum}).reset_index() print df.groupby(by='col1').agg({'col2':['max', 'min']}).reset_index() print df.groupby(by=['col1', 'col3']).agg({'col2':sum}).reset_index()
输出结果:
col1 col2 0 a 45 1 b 2 2 c 3 col1 col2 max min 0 a 44 1 1 b 2 2 2 c 3 3 col1 col3 col2 0 a aa 45 1 b bb 2 2 c cc 3
相关文章推荐
- Python DataFrame.groupby()聚合函数,分组级运算
- 【python】DataFrame.groupby()聚合,分组级运算
- 用python做数据分析4|pandas库介绍之DataFrame基本操作 by 是蓝先生
- 【跟着stackoverflow学Pandas】--Converting a Pandas GroupBy object to DataFrame-Groupby对象转换为DataFrame
- Spark DataFrame 的 groupBy vs groupByKey
- 00017: Data frame has at least one annotation group that is enabled and contains graphics
- Python的groupby
- python itertool.groupby使用误点!
- In R, how to split/subset a data frame by factors in one column?
- .python-eggs is writable by group/others and vulnerable to attack when used with get_resource_filena
- Python中处理DataFrame,R绘图
- python 数据处理学习pandas之DataFrame(三)
- CAML query for Group by count and data
- python的dataframe和matrix的互换
- Python 数据处理扩展包: pandas 模块的DataFrame介绍(读写数据库的操作)
- python连接数据库,tushare,Dataframe to sql
- python groupby
- ORA-15039: diskgroup not dropped ORA-15073: diskgroup DATA1 is mounted by another ASM instance
- Python dataframe to array
- JavaScript SUM and GROUP BY of JSON data