input:
Date letters numbers mixed new
0 1/2/2014 a 6 z1 1/2/2014 a
1 1/2/2014 a 3 z1 1/2/2014 a
2 1/3/2014 c 1 x3 1/3/2014 c
I want to groupby new
and sum numbers
so that the output is:
Date letters numbers mixed new
0 1/2/2014 a 9 z1 1/2/2014 a
1 1/3/2014 c 1 x3 1/3/2014 c
I've looked through here: http://pandas.pydata.org/pandas-docs/stable/groupby.html but no luck.
Here is my code:
import pandas
a=[['Date', 'letters', 'numbers', 'mixed'], ['1/2/2014', 'a', '6', 'z1'], ['1/2/2014', 'a', '3', 'z1'], ['1/3/2014', 'c', '1', 'x3']]
df = pandas.DataFrame.from_records(a[1:],columns=a[0])
f=[]
for i in range(0,len(df)):
f.append(df['Date'][i] + ' ' + df['letters'][i])
df['new']=f
Also, any tricks that will concatenate date
and letters
without looping thru would also be helpful.