【发布时间】:2019-04-23 11:06:26
【问题描述】:
假设我们有以下 pandas 系列是由 groupby 之后应用于数据帧的 apply 函数产生的。
<class 'pandas.core.series.Series'>
0 (1, 0, [0.2, 0.2, 0.2], [0.2, 0.2, 0.2])
1 (2, 1000, [0.6, 0.7, 0.5], [0.1, 0.3, 0.1])
2 (1, 0, [0.4, 0.4, 0.4], [0.4, 0.4, 0.4])
3 (1, 0, [0.5, 0.5, 0.5], [0.5, 0.5, 0.5])
4 (3, 14000, [0.8, 0.8, 0.8], [0.6, 0.6, 0.6])
dtype: object
当给定 sigList=['sig1','sig2', 'sig3'] 时,我们可以将其转换为数据帧吗?
Length Distance sig1Max sig2Max sig3Max sig1Min sig2Min sig3Min
1 0 0.2 0.2 0.2 0.2 0.2 0.2
2 1000 0.6 0.7 0.5 0.1 0.3 0.1
1 0 0.4 0.4 0.4 0.4 0.4 0.4
1 0 0.5 0.5 0.5 0.5 0.5 0.5
3 14000 0.8 0.8 0.8 0.6 0.6 0.6
提前致谢
【问题讨论】:
-
def myfunc(x,signatures): return x.shape[0], x['start'].iloc[-1] - x['start'].iloc[0], x[signatures].agg(max), x[signatures].agg(min)这个函数在元组中创建列表。我们可以在 return 语句中展平列表吗?
标签: python pandas dataframe series