-
1.数据分析的含义与目标查看全部
-
Python数据分析概述查看全部
-
本节代码 #pandas表统计与整合 #均值 print(df.mean()) #方差 print(df.var()) s=pd.Series([1,2,4,np.nan,5,7,9,10],index=dates) print(s) print(s.shift(2)) print(s.diff()) print(s.value_counts()) #累加 print(df.apply(np.cumsum)) #极差 print(df.apply(lambda x:x.max()-x.min())) #表格拼接 pieces=[df[:3],df[-3:]] print (pieces) left=pd.DataFrame({"key":["x","y"],"value":[1,2]}) right=pd.DataFrame({"key":["x","z"],"value":[3,4]}) print("LEFT:",left) print("RIGHT:",right) print(pd.merge(left,right,on="key",how="outer")) df3=pd.DataFrame({"A":["a","b","c","d"],"B":list(range(4))}) print(df3.groupby("A").sum())查看全部
-
本节代码 df1=df.reindex(index=dates[:4],columns = list("ABCD")+["G"]) df1.loc[dates[0]:dates[1],"G"]=1 print (df1) #丢弃数据 print(df1.dropna()) #填充数据 print(df1.fillna(value=1))查看全部
-
def main(): import pandas as pd from matplotlib import pyplot as plt import numpy as np print(df.head(3)) print(df.tail(3)) print(df.index) print(df.values) #T表示转置 print(df.T) #sort_index(axis=1,ascending=False)按照属性值进行降序排序 print(df.sort_index(axis=1,ascending=False)) #describe()函数展示出每列数值的最大,最小,均值,四分位数 print(df.describe()) #DataFrame 只由多个Series构成的 #选择Select,可以进行切片操作 print(type(df["A"])) print(df[:3]) print(df["20170301":"20170304"]) print(df.loc[dates[0]]) print(df.loc["20170301":"20170304",["B","D"]]) print(df.at[dates[0],"C"]) #使用iloc进行特定值得索引,切片操作 print(df.iloc[1:3,2:4]) print(df.iloc[1,4]) print(df.iat[1,4]) #Set s1=pd.Series(list(range(10,18)),index=pd.date_range("20170301",periods=8)) df["F"]=s1 print (df) df.at[dates[0],"A"]=0 print(df) df.iat[1,1]=1 df.loc[:,"D"]=np.array([4]*len(df)) print(df) if __name__ =="__main__": main()查看全部
-
学习学习查看全部
-
111查看全部
-
ndarray的属性查看全部
-
Python数据分析2查看全部
-
Python数据分析查看全部
-
456查看全部
-
123查看全部
-
Anaconda 工具查看全部
-
plt.xticks([-np.pi,-np.pi/2,0,np.pi/2,np.pi]) plt.yticks(np.linspace(-1,1,5,endpoint=True)) for label in ax.get_xticklabels()+ax.get_yticklabels(): label.set_fontsize(16) label.set_bbox(dict(facecolor="white",edgecolor="None",alpha=0.2)) plt.legend(loc="upper left") plt.grid() #plt.axis([-1,1,-0.5,1]) plt.fill_between(x,np.abs(x)<0.5,c,c>0.2,color="green",alpha=0.25) t=1 plt.plot([t,t],[0,np.cos(t)],linewidth=3,line) plt.annotate("cos(1)",xy=(t,np.cos(t)),xytest=(1.5,0.6),testcoords="offset points", arrowprops=dict(arrow,facecolor="black",shrink=0.05,connection)) plt.show() if __name__ == '__main__': main()查看全部
-
import numpy as np def main(): #line import matplotlib.pyplot as plt x=np.linspace(-np.pi,np.pi,256,endpoint=True) c,s=np.cos(x),np.sin(x) plt.figure(2) plt.plot(x,c,color="blue",linewidth=1,line,label="COS",alpha=0.5) plt.plot(x,s,"r*",label="SIN") plt.title("sin&cos") ax=plt.gca() ax.spines["right"].set_color("none") ax.spines["top"].set_color("none") ax.spines["left"].set_position(("data",0)) ax.spines["bottom"].set_position(("data",0)) ax.xaxis.set_ticks_position("bottom") ax.yaxis.set_ticks_position("left")查看全部
举报
0/150
提交
取消