1
I’m not able to create a csv file with a new column (month). When I try to create the whole column is only with the month of December(12) but the month column should correspond to the whole number of the month. Anyway, follow the code:
import pandas as pd
dfdados = pd.read_csv('DadosClimaticos2018Londrina.csv', sep =';')
x = 0
while x <= 1096:
linha = dfdados.iloc[x]
data = linha ['Data']
dia_mes_ano = data.split('/')
print(dia_mes_ano)
x = x + 1
dfdados['Mês'] = dia_mes_ano[1]
dfdados.to_csv('Dadoss.csv',sep = ';',index = False)
Your code misses if you do not specify the date format. At least on my computer it assumed month/day/year and so would have to use
.day
in place of.month
– Flavio Moraes
yes, but in the case of the example, the month will be in element 1 regardless of how your system is defined. In your solution you could use dayfirst=True
– Flavio Moraes
Thank you! It helped a lot. If you don’t mind, can you take a look at my other question? https://answall.com/q/481747/212837
– gabriela
Gabriela, good morning! I’m glad you decided! If the answer has solved your problem, consider marking the answer as valid (not required but is a good practice for future users with the same problem). See how. I visited the other question and left a suggestion to solve the problem. Hugs!
– lmonferrari