Realize function
Python data analysis actual combat - dataframe grouping (summing a certain column)
1、df.groupby()[].sum().to_frame().reset_index()
2、df.columns=[]
Implementation code
import pandas as pd
# 读取数据
data=pd.read_csv('E:\数据杂坛\\UCI Heart Disease Dataset.csv')
df=pd.DataFrame(data)
print(df.head())
# 按target分组求和(对所有列求和)
df1=df.groupby('target').sum().reset_index()
print(df1)
# 按target分组求和(只对age求和)
df2=df.groupby('target')['age'].sum().reset_index()
print(df2)
achieve effect
During my postgraduate study, I published 5 papers related to SCI data mining. Now a research institute is engaged in scientific research related to data mining. I have a certain knowledge and understanding of data mining. I will combine my own scientific research practice experience to share from time to time about python machine learning and deep learning. , Basic knowledge and cases of data mining.
Committed to only being original, understanding and learning in the simplest way, pay attention to the V subscription number: data miscellaneous forum, contact me for more skills and source code.