pandas datetime operations, indexing, and slicing – a refresher
Instead of using our dataset, which is slightly complex, let’s pick an easy, well-formatted stock exchange price dataset from the UCI Machine Learning Repository and look at the functionality of pandas:
df = pd.read_excel("https://archive.ics.uci.edu/ml/machine-learning-databases/00247/data_akbilgic.xlsx", skiprows=1)
The DataFrame that we read looks as follows:
Figure 2.2 – The DataFrame with stock exchange prices
Now that we have read the DataFrame, let’s start manipulating it.
Converting the date columns into pd.Timestamp/DatetimeIndex
First, we must convert the date column (which may not always be parsed as dates automatically by pandas) into pandas datetime. For that, pandas has a handy function called pd.to_datetime
. It infers the datetime format automatically and converts the input into a pd.Timestamp
, if the input is a string
, or...