In [6]:
import pandas as pd
import numpy as np
from numpy.random import randn
np.random.seed(3)
m1=randn(5,4)
In [7]:
df1=pd.DataFrame(m1,["a","b","c","d","e"],["w","x","y","z"])
In [7]:
df1
Out[7]:
In [8]:
df1['w']
Out[8]:
In [9]:
df1
Out[9]:
In [10]:
df1>0
Out[10]:
In [11]:
z=df1>0
In [12]:
z
Out[12]:
In [15]:
df1[z]
Out[15]:
In [19]:
df1[df1<0]
Out[19]:
In [20]:
df1
Out[20]:
In [22]:
df1[df1["w"]>0]
Out[22]:
In [45]:
df1[df1['w']>0]['y']
print(df1)
In [25]:
df1[df1['w']>0][['y','x']]
Out[25]:
In [33]:
df1['w']>0
Out[33]:
In [34]:
bs=df1['w']>0
In [46]:
bs
Out[46]:
In [37]:
res=df1[bs]
In [47]:
res
Out[47]:
In [52]:
res[["x","y"]]
Out[52]:
In [44]:
res[['x','y']]
Out[44]:
In [53]:
z=["x","y"]
In [54]:
res[z]
Out[54]:
In [55]:
df1
Out[55]:
In [66]:
df1[(df1["x"]>0) |(df1["y"]>0)]
Out[66]:
In [9]:
(df1["x"]>0)| (df1["y"]>0 )
Out[9]:
In [63]:
(df1["x"]>0) & (df1["y"]>0 ) & (df1["z"]>0 )
Out[63]:
In [64]:
df1[(df1["x"]>0) & (df1["y"]>0 ) & (df1["z"]>0 )]
Out[64]:
In [1]:
True and True
Out[1]:
In [2]:
True and False
Out[2]:
In [3]:
True or False
Out[3]:
In [10]:
df1
Out[10]:
In [18]:
df2.reset_index(inplace=True)
In [13]:
df2=df1
In [19]:
df2
Out[19]:
In [20]:
in1=["AP","tg","ks","nk","ph"]
In [21]:
df1["states"] =in1
In [25]:
df1
Out[25]:
In [26]:
df1.set_index("states",imp)
Out[26]:
In [24]:
df1
Out[24]:
In [27]:
df1
Out[27]:
No comments:
Post a Comment