I try to import a excel file get all dates from a column with dates and count how many events i have every year on all days of year from 2012 till now. And i have this error: ValueError(f"cannot insert {column}, already exists") ValueError: cannot insert Date, already exists
import pandas as pd
file_path = r'C:\Users\xxx\Desktop\yyy.xlsx'
data = pd.read_excel(file_path)
data['Date'] = pd.to_datetime(data['AVVIATO'])
data['Year'] = data['Date'].dt.year
data['DayOfYear'] = data['Date'].dt.dayofyear
df = data.groupby([pd.Grouper(key='Date', freq='D'), pd.Grouper(key='Date', freq='Y')]).size().reset_index(name='counts')
df['CumulativeSum'] = df.groupby('Date')['counts'].cumsum()
df['YearCount'] = df.groupby('Year').cumcount() + 1
export_path = r'C:\Users\adrcl\Desktop\output.xlsx'
df.to_excel(export_path, index=False)
source https://stackoverflow.com/questions/75850176/valueerror-cannot-insert-date-already-exists
Comments
Post a Comment