pandas模块-函数映射&排序&重复轴判断
导入模块
import numpy as np
import pandas as pd
from pandas import Series,DataFrame
1.函数应用和映射
先创建一个DataFrame
df1=DataFrame(
np.random.choice(range(20),size=(4,3),replace=False)
index=list('ABCD')
columns=list('abc')
)
df1
(1)使用numpy的函数操作, axis=0/1跨行/列操作
(1.1)求和
np.sum(df1,axis=0)
np.sum(df1,axis=1)
np.sum([[0,1],[0,5]],axis=0)
np.sum([[0,1],[0,5]],axis=1)
#因为后面定义了类型是int,所以小数全部舍去只保留整数位
np.sum([0.5,0.7,0.2,1.5],dtype=np