plot two Y axis
fig, ax = plt.subplots(figsize=(12,6))
ax.plot(df['TradeVal'],color="blue")
ax.set_ylabel("TradeVal",color="blue",fontsize=14)
# twin object for two different y-axis on the sample plot
ax2=ax.twinx()
plt.plot( (df['midPrice'] /df['midPrice'].iloc[0]-1)*100 ,color="red" )
# make a plot with different y-axis using second axis object
ax2.set_ylabel("midPrice[%]",color="red",fontsize=14)
plt.grid()
plt.show()
df = pd.DataFrame(np.random.uniform(0,1,(3,5)))
df.columns = [f'range{i}' for i in range(0,5)]
mft = [True]*3
df2 = df.loc[mft] #this is a copy
df2 = df.loc[mft,:] #this is a copy
df2 = df[mft] #this is a copy
df[df>0.5] =0 #this is inplace change
A=pd.DataFrame([[0,0,0],[0,0,0],[0,0,0]],columns=['c1','c2','c3'])
B=A.loc[0] #loc单选一个index 或一个column是view
BBB=A.loc[[0,2]] #loc进行[ ] or () 选择是copy
BB=A.loc[:,"c1"] #loc单选一个index 或一个column是view
C=A.loc[0:1] #对index或者column 进行slice是view
C1=A.loc[0:1,['c1','c2']] #loc进行[ ] or () 选择是copy
C2=A.loc[0:1,'c1'] #view
D=A.loc[A.index<2] #loc进行boolean筛选是copy
A.at[0,'c1']=1
print('A......')
print(A)
print('B......')
print(B)
print('BB......')
print(BB)
print('BBB......')
print(BBB)
print('C......')
print(C)
print('C1......')
print(C1)
print('C2......')
print(C2)
print('D......')
print(D)
对index或者column 进行slice是view
loc单选一个index 或一个column是view
loc多选(index有重复)得到copy(和series 有出入,注意!!)
loc进行boolean筛选是copy
loc进行[ ] or () 选择是copy
使用1.2.3.4.5.对frame同时进行index和column的操作,当且仅当index和column都是结果为view操作时,返回的frame或series才是view,其他是copy