I have a set of data that extracted from an excel sheet. one of the columns were dates and so I used df.to_datetime()
to reformat the data. The data I have is only for the first day of each month, the string format is:
"20190101"
so there are only 12 dates.
Then I used pd.pivot to make this column of dates the column labels. The plan now is to subset the columns by seasons (e.g Jan, Feb, Dec is winter). I only have 2019 data but I will be using this code for future years. I will be taking Dec of previous year so I need to disregard the years.
How do I subset the columns based on the months. In other words I want to divide the DataFrame similarly to:
for column in full_df.iterrows()
If (column_label.datetime.month = 01 | column_label.datetime.month = 02 |column_label.datetime.month = 12):
winter_df[datetime.month] = full_df[column_label]
I know for loops are frowned upon in Dataframe, and I know I can hard-code it by keeping it as a string and typing in the specific strings, but the data will not be from the same year each time and I would have to adjust the code every year.
How do I do an if statement for column labels? df.filter()
might be a good idea but I don't know if its possible with datetime object.
P.S. forgive me if I formed the question poorly or I don't understand your answer. Fairly new to pandas.
Update: I am looking to split the DataFrame into three based on month, The three periods of time are as follows: Winter: January ,February ,December Light load: March, April, May Summer: June,July August, September