标签:ror density any pandas font select pre type max
import numpy as np import pandas as pd np.add()/df.add() 加法运算 + np.aubtract()/df.aubtract() 减法运算 - np.megative() 负数运算 - np.multiply() 乘法运算 * np.divide() 除法运算 / np.floor_dicide() 向下整除 // np.power() 指数运算 ** np.mod() 求余数 % np.abs() 求绝对值 np.sin() ,cos(), tan() 求正弦 余弦 正切 np.exp(x) e为底的x次方 np.exp2(x),2为底的x次方 np.log(x) e为底对x开根号 np.log2(x) 2为底 np.sum() min() max() 求和 求最小值 求最大值 axis=0 列 axis=1 行 np.prod() 计算元素的积 np.mean() 计算元素的平均值 np.std() 计算元素的标准差 np.var() 计算元素的方差 np.argmin()找出最小值的索引 np.median()计算元素的中位数 np.any() 验证是否存在元素为真 np.all() 验证所有元素是否为真
Out[46]:
data=pd.Series([0.25,0.5,0.75,1.0])#Series是一个带索引的一维数组 data
data.index#可获取索引与值
data.values
data[0]#可切片
data.index=["a","b","c","d"]#可定义索引 data
population_dic={"california":423967,"texas":695663,"new york":141297,"florida":170312,"tllinois":149995} population=pd.Series(population_dic) population
area_dict={"california":423967,"texas":695663,"new york":141297,"florida":170312,"tllinois":149995} aeea=pd.Series(area_dict) aeea
states=pd.DataFrame({"population":population,"aeea":aeea})#DataFrom是特殊的二维字典,一个标题行对应一列数据,创建时用字典格式创建 states
states.index
states.columns
states["aeea"]
pd.DataFrame(population,columns=["population"])#创建单列
Out[13]:
data=[{"a":i,"b":i*2}for i in range(5)] pd.DataFrame(data)
pd.DataFrame(np.random.rand(3,2),index=(["a","b","c"]),columns=["foo","bar"])
data=pd.Series([0.25,0.5,0.75,1.0],index=["a","b","c","d"])#Series是一个带索引的一维数组 data
data["e"]=1.25#添加数据 data
#切片应用
data["a":"c"]
data[0:2]
data[(data>0.3)&(data<0.8)]
Out[20]:
data=pd.Series(["a","b","c"],index=[1,3,5]) data
data.loc[1]#看得见的索引
data.loc[1:3]
data.iloc[1]#看不见的索引
Out[24]:
data.iloc[1:3]
#DataFrame的数据选择方法 area=pd.Series({"california":423967,"texas":695663,"new york":141297,"florida":170312,"tllinois":149995}) pop=pd.Series({"california":33323967,"texas":33395663,"new york":11111297,"florida":22220312,"tllinois":22229995}) data=pd.DataFrame({"area":area,"pop":pop}) data
data["area"]
Out[27]:
data.area
data["density"]=data["pop"]/data["area"]#增加一列
data
data.values#查看数据
data.T#转置
Out[31]:
data.loc[data.density>100,["pop","density"]]
data.iloc[0,2]=90#修改数据 data
data[data.density>100]#掩码过滤
Out[34]:
#pandas 的数值运算方法 import numpy as np import pandas as pd
rng=np.random.RandomState(42) ser=pd.Series(rng.randint(0,10,4)) ser
Out[36]:
df=pd.DataFrame(rng.randint(0,10,(3,4)),columns=["A","B","C","D"]) df
np.exp(ser)
np.sin(df*np.pi/4)
ser//2
标签:ror density any pandas font select pre type max
原文地址:https://www.cnblogs.com/Koi504330/p/11909272.html