pandas, iloc, ix, loc difference

These three variables used for the first dimension, iloc front opening closed (with numpy, python list), after ix, iloc when a front closed closed interval.

Bug good design.

import numpy as np
import pandas as pd

df = pd.DataFrame(np.random.uniform(0,5, [10,2]))
print(df)
print(df.iloc[:3, 1])
print(df.loc[:3, 1])
print(df.ix[:3, 1])

The results hint:

          0         1
0  1.416366  3.784376
1  0.960108  1.646960
2  1.140056  2.993692
3  0.038732  1.769343
4  2.582050  4.780281
5  0.619522  2.427872
6  2.004104  2.310061
7  2.374742  0.876965
8  3.716511  1.882538
9  1.344465  1.324901

0    3.784376
1    1.646960
2    2.993692
Name: 1, dtype: float64

0    3.784376
1    1.646960
2    2.993692
3    1.769343
Name: 1, dtype: float64

0    3.784376
1    1.646960
2    2.993692
3    1.769343
Name: 1, dtype: float64

 

Published 36 original articles · won praise 0 · views 20000 +

Guess you like

Origin blog.csdn.net/weixin_38102912/article/details/101051779