lst = [['henry', 10, 20], ['henry', 23, 42], ['alex', 25, 40]]
import pandas as pd
#Create a dataframe using the list
df = pd.DataFrame(lst)
#Name the columns
df.columns = ['name', 'val1', 'val2']
#Groupby name and sum it.
df.groupby('name').sum()
#Will produce this result
val1 val2
name
alex 25 40
henry 33 62
#To access the rows and columns following is the example
dfg = df.groupby('name').sum()
#Row, Column
dfg.ix[0,0]
#Will get 25 & likewise can get any other values
25
IIUC这里有一个使用^{} 的解决方案:
相关问题 更多 >
编程相关推荐