How to add pandas data to an existing csv file? -


i want know if possible use pandas to_csv() function add dataframe existing csv file. csv file has same structure loaded data.

you can append csv opening file in append mode:

with open('my_csv.csv', 'a') f:     df.to_csv(f, header=false) 

if csv, foo.csv:

,a,b,c 0,1,2,3 1,4,5,6 

if read , append, example, df + 6:

in [1]: df = pd.read_csv('foo.csv', index_col=0)  in [2]: df out[2]:     b  c 0  1  2  3 1  4  5  6  in [3]: df + 6 out[3]:       b   c 0   7   8   9 1  10  11  12  in [4]: open('foo.csv', 'a') f:              (df + 6).to_csv(f, header=false) 

foo.csv becomes:

,a,b,c 0,1,2,3 1,4,5,6 0,7,8,9 1,10,11,12 

Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -