0
Hello. Using the code below I perform a monthly average, but it is fixed on the last day of the current month and I would like to know if it is possible to configure it for a fixed day of the month as the first day or the 15th for example.
In the code, 123456789.csv is a generic archive with daily data for a few years from which monthly averages and the index_col is setting the date as index.
file0 = pd.read_csv('123456789.csv', sep = ',', index_col = 0)
file0.index = pd.to_datetime(file0.index)
monthly_mean = file0.resample('M').mean()
This would be an example of the original output:
                  Dados
Data                      
2006-01-31        4.206452
2006-02-28        3.878571
2006-03-31        4.038710
2006-04-30        4.113333
2006-05-31        4.306452
...                    ...
2014-08-31        4.312903
2014-09-30        4.456667
2014-10-31        3.958065
2014-11-30        3.950000
2014-12-31        3.661290
And that would be an example of a result:
                  Dados
Data                      
2006-01-15        4.206452
2006-02-15        3.878571
2006-03-15        4.038710
2006-04-15        4.113333
2006-05-15        4.306452
...                    ...
2014-08-15        4.312903
2014-09-15        4.456667
2014-10-15        3.958065
2014-11-15        3.950000
2014-12-15        3.661290
						
You can make the file available
123456789.csvor an equivalent example?– Lucas
This is a very pertinent question. Starting from version 1.1 of pandas, there is an option to
offsetand one oforiginin theDataFrame.resample, but none of them seem to work for months. The solution I could think of is to subtract 15 days from the date, resample and correct the date in the resample output. But I threw a question in the stack in English to see if anyone gives a better suggestion.– Flavio Moraes