This article brings you an in-depth understanding of Pandas in python (code examples). It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
First create a 6X4 matrix data.
dates = pd.date_range('20180830', periods=6) df = pd.DataFrame(np.arange(24).reshape((6,4)),index=dates, columns=['A','B','C','D']) print(df)
Print:
A B C D 2018-08-30 0 1 2 3 2018-08-31 4 5 6 7 2018-09-01 8 9 10 11 2018-09-02 12 13 14 15 2018-09-03 16 17 18 19 2018-09-04 20 21 22 23
If we want to select the data in DataFrame
, two ways are described below, they can To achieve the same goal:
print(df['A']) print(df.A) """ 2018-08-30 0 2018-08-31 4 2018-09-01 8 2018-09-02 12 2018-09-03 16 2018-09-04 20 Freq: D, Name: A, dtype: int64 """
To make the selection span multiple rows or columns:
print(df[0:3]) """ A B C D 2018-08-30 0 1 2 3 2018-08-31 4 5 6 7 2018-09-01 8 9 10 11 """ print(df['20180830':'20180901']) """ A B C D 2018-08-30 0 1 2 3 2018-08-31 4 5 6 7 2018-09-01 8 9 10 11 """
If df[3:3]
will be an empty object. The latter selects data between the tags 20180830
to 20180901
, and includes these two tags .
You can also select via loc
, iloc
, ix
.
Related recommendations:
A brief introduction to using the Pandas library to process big data in Python
Through pandas in Python Detailed explanation of the library's analysis of cdn logs
The above is the detailed content of In-depth understanding of Pandas in python (code examples). For more information, please follow other related articles on the PHP Chinese website!