Let's create a data frame by hand.
[Python]View PlainCopy
- Import NumPy as NP
- Import Pandas as PD
- DF = PD. DataFrame (Np.arange (0,2). Reshape (3), columns=list (' abc ' )
DF is such a drop
So how do you choose the three ways to pick the data?
One, when each column already has column name, with DF [' a '] can choose to take out a whole column of data. If you know column names and index, and both are well-entered, you can choose. loc
[Python]View PlainCopy
- df.loc[0, ' a ']
- df.loc[0:3, [' a ', ' B ']
- df.loc[[1, 5], [' B ', ' C ']]
Because this side we did not name index, so is dataframe automatically assigned, for the number 0-9
Second, if we suspect that column name is too long, input inconvenient, or index is a column of time series, more bad input, then you can choose. Iloc. This side I I think the representative index, better to remember points.
[Python]View PlainCopy
- df.iloc[1,1]
- df.iloc[0:3, [0,1]]
- df.iloc[[0, 3, 5], 0:2]
Iloc allows us to select the data using the slice (slice) method of column.
Third,. IX features are more powerful, it allows us to mix the subscript and the name of the selection. It can be said that it covers all the previous uses. Basically change the front to Df.ix can be successful, but one thing is that
Df.ix [[.. 1 ...], [.. 2.]], the 1 box must be unified, must also be subscript or name, 2 box is also the same. BTW, the 1 box is used to specify that the row,2 box is the specified column, and all of the above methods are, of course, the rule.
This is my current understanding.
Python pandas. Dataframe the best way to select and modify data. Loc,.iloc,.ix