I have a pandas
DF that looks like this
DF:
name ;time_cost
x ;28800000, 250
x ;39600000, 300
x ;61200000, 250
x ;72000000, 0
y ;86400000, 0
y ;115200000, 250
y ;126000000, 300
y ;147600000, 250
y ;158400000, 0
df.head().to_dict()
{'name': {0: 'x',
1: 'x',
2: 'x',
3: 'x'},
'time_cost': {0: '28800000, 250',
1: '39600000, 300',
2: '61200000, 250',
0: '72000000, 0'}}
I'm trying to put all the values from time_cost into an array like so:
[[[28800000, 250],
[39600000, 300],
[61200000, 250],
[72000000, 0 ],
[86400000, 0 ]],
[[115200000, 250],
[126000000, 300],
[147600000, 250],
[158400000, 0]]]
Here's what I have tried:
import pandas as pd
df = pd.read_csv('file.csv', sep=';')
def f(df):
return pd.Series(dict(timecost_range = "%s" % '| '.join(df['time_cost'])))
result = df.groupby('name').apply(f)
result
timecost_range
name
x 28800000, 250| 39600000, 300| 61200000, 250| 72000000, 0
y 86400000, 0| 115200000, 250| 126000000, 300| 147600000, 250|...
This works somewhat, but isn't exactly what I am looking for. Any ideas or suggestions would be useful.