I have the following column:
0 3012022.0
1 3012022.0
2 3012022.0
3 3012022.0
4 3012022.0
...
351 24032022.0
352 24032022.0
df.Data = df.Data.astype('str')
I converted the float to string and I'm trying to transform them in datetype:
df['data'] = pd.to_datetime(df['data'], format='%d%m%Y'+'.0').dt.strftime('%d-%m-%Y')
output: ValueError: day is out of range for month
the code is:
os.chdir('/home/carol/upload')
for file in glob.glob("*.xlsx"):
xls = pd.ExcelFile('/home/carol/upload/%s'%(file))
if len(xls.sheet_names) > 1:
list_sheets= []
for i in xls.sheet_names:
df = pd.read_excel(xls, i)
list_sheets.append(df)
df = pd.concat(list_sheets)
else:
df = pd.read_excel(xls)
df = df[['Data','Frota','Placa','ValorFrete', 'ValorFaturado','CodFilial','NomeFilial']]
df = df.dropna()
df = df.apply(lambda x: x.astype(str).str.lower())
df.columns = df.columns.str.lower()
df.columns = df.columns.str.normalize('NFKD').str.encode('ascii', errors='ignore').str.decode('utf-8')
df= df.apply(lambda x: x.str.normalize('NFKD').str.encode('ascii', errors='ignore').str.decode('utf-8'))
df['data'] = pd.to_datetime(df['data'].astype(str).str.split('\.').str[0], format='%d%m%Y')