Appending a list or series to a pandas DataFrame as a row?
--------------------------------------------------
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Droplet of life
--
Chapters
00:00 Appending A List Or Series To A Pandas Dataframe As A Row?
00:18 Answer 1 Score 192
00:26 Accepted Answer Score 182
00:46 Answer 3 Score 71
00:59 Answer 4 Score 42
01:17 Answer 5 Score 33
01:34 Thank you
--
Full question
https://stackoverflow.com/questions/2630...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #pandas #append #dataframe
#avk47
    Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Droplet of life
--
Chapters
00:00 Appending A List Or Series To A Pandas Dataframe As A Row?
00:18 Answer 1 Score 192
00:26 Accepted Answer Score 182
00:46 Answer 3 Score 71
00:59 Answer 4 Score 42
01:17 Answer 5 Score 33
01:34 Thank you
--
Full question
https://stackoverflow.com/questions/2630...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #pandas #append #dataframe
#avk47
ACCEPTED ANSWER
Score 183
Sometimes it's easier to do all the appending outside of pandas, then, just create the DataFrame in one shot.
>>> import pandas as pd
>>> simple_list=[['a','b']]
>>> simple_list.append(['e','f'])
>>> df=pd.DataFrame(simple_list,columns=['col1','col2'])
   col1 col2
0    a    b
1    e    f
ANSWER 2
Score 71
Here's a simple and dumb solution:
>>> import pandas as pd
>>> df = pd.DataFrame()
>>> df = df.append({'foo':1, 'bar':2}, ignore_index=True)
ANSWER 3
Score 42
Could you do something like this?
>>> import pandas as pd
>>> df = pd.DataFrame(columns=['col1', 'col2'])
>>> df = df.append(pd.Series(['a', 'b'], index=['col1','col2']), ignore_index=True)
>>> df = df.append(pd.Series(['d', 'e'], index=['col1','col2']), ignore_index=True) 
>>> df
  col1 col2
0    a    b
1    d    e
Does anyone have a more elegant solution?
ANSWER 4
Score 33
Following onto Mike Chirico's answer... if you want to append a list after the dataframe is already populated...
>>> list = [['f','g']]
>>> df = df.append(pd.DataFrame(list, columns=['col1','col2']),ignore_index=True)
>>> df
  col1 col2
0    a    b
1    d    e
2    f    g