In [5]:
import pandas as pd
import numpy as np
df = pd.DataFrame(np.random.randn(5, 3), index=['a', 'c', 'e', 'f', 'h'],columns=['one', 'two', 'three'])
df['four'] = 'bar'
df['five'] = df['one'] > 0
df


Out[5]:
one two three four five
a -0.736298 0.546626 -0.688422 bar False
c 1.271292 0.054160 -0.320729 bar True
e -0.637428 -1.005087 -1.219964 bar False
f 0.308531 0.196214 -0.312641 bar True
h 1.066718 0.705849 -0.099920 bar True

In [6]:
df2 = df.reindex(['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'])
df2


Out[6]:
one two three four five
a -0.736298 0.546626 -0.688422 bar False
b NaN NaN NaN NaN NaN
c 1.271292 0.054160 -0.320729 bar True
d NaN NaN NaN NaN NaN
e -0.637428 -1.005087 -1.219964 bar False
f 0.308531 0.196214 -0.312641 bar True
g NaN NaN NaN NaN NaN
h 1.066718 0.705849 -0.099920 bar True

In [7]:
dff = pd.DataFrame(np.random.randn(10,3),columns=list('ABC'))
dff.iloc[3:5,0] = np.nan

dff.iloc[4:6,1] = np.nan

dff.iloc[5:8,2] = np.nan

In [17]:
dff.mean()['B':"C"]
pd.Series([1,0],index=list('BC'))


Out[17]:
B    1
C    0
dtype: int64

In [18]:
dff.fillna(pd.Series([1,0],index=list('BC')))


Out[18]:
A B C
0 1.055356 0.736670 0.321692
1 -1.464509 -0.453976 -1.348463
2 -0.665578 0.423287 0.429259
3 NaN -1.037082 0.012615
4 NaN 1.000000 -0.089787
5 -2.764632 1.000000 0.000000
6 -0.613470 -0.392313 0.000000
7 -1.877400 0.364823 0.000000
8 0.191521 -0.406305 -1.861625
9 -1.860177 -0.548034 -0.302685

In [20]:
d = {'a': list(range(4)), 'b': list('ab..'), 'c': ['a', 'b', np.nan, 'd']}
df = pd.DataFrame(d)
df


Out[20]:
a b c
0 0 a a
1 1 b b
2 2 . NaN
3 3 . d

In [ ]: