A data frame object for handling structured data in Python. You can easily read files and perform subsequent SQL operations, and it is necessary for work such as machine learning to process, calculate, and visualize data. A memo list of commonly used syntaxes for data manipulation. This section is date-time processing. The table of contents for other items is here.
Import pandas with the name pd
python
import pandas as pd
Converts the item described in Object type to datetime64 [ns] type (Timestamp type). Suppose you want to convert the item "Day" in the definition of dataframe.
python
dataframe['Day'] = pd.to_datetime(dataframe['Day'])
"Day" extracts the data after "April 1, 2020".
python
dataframe = dataframe.loc[dataframe['Day'] > pd.to_datetime('20200401')]
datetime64 [ns] Converts Day, which is a type, to a date (object type).
python
dataframe['Day'] = pd.to_datetime(dataframe['Day']).dt.date
Recommended Posts