[Python] 纯文本查看 复制代码
import numpy as np
import pandas as pd
df = pd.DataFrame({"区域": ["茂南", "茂南", "茂南", "茂南", "信宜", "茂南", "茂南", "高州", "高州"],
"网格": ["油城南", "西城", "西城", "油城南", "信城南", "油城南", "西城", "高城北", "高城北"],
"装维": ["张学友", "刘德华", "刘德华", "郭富城", "古天乐", "张学友", "周星驰", "张家辉", "张家辉"],
"用户属性": ["普通", "普通", "高端", "普通", "高端", "高端", "普通", "高端", "普通"],
"拜访次数": [1, 2, 2, 3, 3, 4, 5, 6, 7],
"收益": [2, 4, 5, 5, 6, 6, 8, 9, 9]})
print(df)
df2 = pd.pivot_table(df, values=['用户属性', '收益'], index=['装维个人'], aggfunc=np.sum)
print(df2)