I have tried the following code:
import pandas as pd
list1 = {'Names':[1,2,3,4,5]}
df = pd.DataFrame(list1)
df_csv = pd.read_csv('try.csv')
df_csv['Names'] = list1
df_csv.to_csv('try.csv', index=False, mode= 'a')
The error is as following:
"ValueError: Length of values does not match length of index"
I understand that the size of the dataframe doesn't match but how can I solve that?
So, this is what I want in try.csv file after appending: try.csv file
df_csv['Names'] = list1['Names']df_csv['Names'] = pd.DataFrame(list1)instead ofdf_csv['Names'] = list1