Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed. https://blog.csdn.net/a19990412/article/details/90980403
change
- format: representation str style
- errors: If the bug occurs, and then how to deal with (raise indicates that an give me burst out)
df['date'] = pd.to_datetime(df['date'], format='%Y-%m-%d', errors='raise')
Commonly used format in addition to the above are:
%Y/%m/%d
%Y年%m日%d
- …
Sort is no problem
- Sorted by date
After the first change to the operation of Kazakhstan
df.sort_values(by='date')
- More in this parameter: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.sort_values.html
- Including reverse and filling
Choose a specific year
- It is first mapped to a Boolean the Series, to do projection Projection
df[df['date'].map(lambda x:x.year == 2018)]
Other similar operations
(Division of year or month intervals, with this operation is similar to here do not go into details, there are requirements to mention the comments section)