Home > Software engineering >  How do I show the Prices on January 1 of 2017, 18, 19, 20, 21, and 22 in my dataframe? Python
How do I show the Prices on January 1 of 2017, 18, 19, 20, 21, and 22 in my dataframe? Python

Time:10-22

Code

I can't figure out how to get the first days of every year so that I can show the change.

CodePudding user response:

Filter the dataframe using the date you want (simple example if the column is named date and you can compare with a string):

data[data['date'] == '2017-01-01']

CodePudding user response:

I suspect your column that holds the dates is unnamed. That column is called index by default even though you don't see that. So in order to iterate that column you will have to do something like this:

date = data.index

To get first date of every year:

first_dates = data.groupby(pd.DatetimeIndex(data.index).to_period('Y')).nth([0])
  • Related