I've been trying to place some new columns in a csv file, but the error "ValueError: cannot reindex from a duplicate axis" appears.
Taking a look at the output, one column is added, but none more. I've googled this for a few hours, and still don't understand the error.
Here is the code:
for filename in [f for f in os.listdir(CSV_DATA_DIR) if isfile(join(CSV_DATA_DIR, f))]:
print(filename)
csv_data = pd.read_csv('data.csv')
csv_input = pd.read_csv(CSV_DATA_DIR + filename
print(csv_data.index)
inputViews = csv_input['Views']
offset = pd.Series([0] * (len(csv_data['Date']) - len(csv_input['Views'])))
inputViews = inputViews.append(offset)
if(len(csv_data['Date']) - len(inputViews) == 0):
csv_data[filename] = inputViews
csv_data.to_csv('data.csv', index=False)
print("done")
Here's an image of the CSV file after the program is run if it helps