Assume this is my csv
file: (df)
id,name,version,ct_id
1,testing,version1,245
2,testing1,version2,246
3,testing2,version3,247
4,testing3,version4,248
5,testing1,version5,249
Now I've performed some operation on the file and write it to another csv
file.
df = pd.read_csv('op.csv')
df1 = df.groupby('name').agg({'version': ', '.join, 'ct_id': 'first'}).reset_index()
df1.to_csv('test.csv', index=False)
Now I've another csv file. (df_1)
id,name,version,ct_id
36,testing17,version16,338
37,testing18,version17,339
I want to write this to my existing test.csv
file which I created earlier but I want to insert these two rows at the beginning of the file rather than at the end.
I tried something like this.
df_1.iloc[:, 1:].to_csv('test.csv', mode='a', index=False)
# This does append but at the end.
I would appreciate if someone could help?