I have an issue with keeping some data from duplicates and wanting to add valuable information to a new column in the dataframe.
import pandas as pd
data = {'id':[1,2,2,3],'company':[1,2,2,1],'bank':['a', 'x', 'y', 'a'],
'round': ['seed', 'seed', 'seed', 'series a'], 'funding': [100, 200, 200, 300],
'date': ['2006-12-01', '2004-09-01', '2004-09-01', '2007-05-01']}
df = pd.DataFrame(data, columns = ['id','company', 'round', 'bank', 'funding', 'date'])
print df
Yields:
id company round bank funding date
0 1 1 seed a 100 2006-12-01
1 2 2 seed x 200 2004-09-01
2 2 2 seed y 200 2004-09-01
3 3 1 series a a 300 2007-05-01
Desired Output:
company round_0 bank_0 funding_0 date_0 round_1 bank_1 funding_1 date_1
0 1 seed a 100 2006-12-01 series a a 300 2007-05-01
1 2 seed [x, y] 200 2004-09-01 None None None None
I'm thinking that a pivot/melt might work? Along with a groupby('company', 'round')?
Also, I'm open to the idea of changing the dtype for the new bank column list (ie dictionary). And, the integers could be replaced with the "round" column info. Making the columns:
company, bank_seed, funding_seed, date_seed, bank_series_a, funding_series_a, date_series_a