This article brings the content is about Python pandas in-depth understanding (code example), there is a certain reference value, the need for friends can refer to, I hope to help you.
First, screening
First, create a 6X4 matrix data.
Dates = Pd.date_range (' 20180830 ', periods=6) df = PD. DataFrame (Np.arange) reshape ((6,4)), index=dates, columns=[' A ', ' B ', ' C ', ' D ']) print (DF)
Print:
A B C d2018-08-30 0 1 2 32018-08-31 4 5 6 72018-09-01 8 9 112018-09-02 152018-09-03 192018-09-04 23
Simple filtering
If we want to select DataFrame
the data, the following describes two ways that they can achieve the same goal:
Print (df[' A ']) print (DF. A) "" "2018-08-30 02018-08-31 42018-09-01 82018-09-02 122018-09-03 162018-09-04 20freq:d, Name:a, Dtype:int64 "" "
Let the selection span multiple rows or columns:
Print (Df[0:3]) "" " A B C d2018-08-30 0 1 2 32018-08-31 4 5 6 72018-09-01 8 9 "" " print (df[' 20180830 ': ' 20180901 '])" "" A B C d2018-08-30 0 1 2 32018-08-31 4 5 6 72018-09-01 8 9 10 11 "" "
If df[3:3]
it will be an empty object. The latter selects the 20180830
20180901
data between the labels and includes both tags .
You can also go through loc
, iloc
and ix
make your choice.