1
I have a database in which one column is the year and the other columns are the total of formal workers in a city (each column a city). My goal is simply to aggregate my annual data to triennials. Here’s a replicable example of what I’ve done so far:
import random
import pandas as pd
from datetime import datetime
df = pd.DataFrame({'Ano': range(1890,1920),
'A': [random.choice(range(0,50)) for k in range(0,30)],
'B': [random.choice(range(0,50)) for k in range(0,30)],
'C': [random.choice(range(0,50)) for k in range(0,30)]},
index=range(0,30))
#tiro um ano de propósito para replicar o fato de que minha base não tem informação para todos os anos
df = df[df['Ano']!=1907]
df['Ano'] = [datetime.strptime(str(k), '%Y') for k in df['Ano']]
df.set_index('Ano', inplace=True)
print(df.resample('3T').sum())
Problem:
- The
3T
I used it based on what I saw in the documentation of pandas, but I don’t think I’ve interpreted this correctly since this command is running for a long time until crashing my computer.
I managed to solve here. What is the correct procedure in this case, post the answer so that other users can see or delete the question?
– Lucas
If you are willing to help, posting the answer is better!
– nosklo