pandas: powerful Python data analysis toolkit - 0.25760109 0.942941 Returning a Series to propagate names Group DataFrame columns, compute a set of metrics and return a named Series. The Series name is used as the name for the column index. This is especially compute_metrics(x): .....: result = {'b_sum': x['b'].sum(), 'c_mean': x['c'].mean()} .....: return pd.Series(result, name='metrics') .....: In [233]: result = df.groupby('a').apply(compute_metrics) In [234]: [234]: result Out[234]: metrics b_sum c_mean a 0 2.0 0.5 1 2.0 0.5 2 2.0 0.5 In [235]: result.stack() Out[235]: a metrics 0 b_sum 2.0 c_mean 0.5 1 b_sum 2.0 c_mean 0.5 2 b_sum 2.0 c_mean 0.5 dtype: float640 码力 | 698 页 | 4.91 MB | 1 年前3
pandas: powerful Python data analysis toolkit - 0.150.15.2 16.10.2 Returning a Series to propagate names Group DataFrame columns, compute a set of metrics and return a named Series. The Series name is used as the name for the column index. This is especially compute_metrics(x): .....: result = {’b_sum’: x[’b’].sum(), ’c_mean’: x[’c’].mean()} .....: return pd.Series(result, name=’metrics’) .....: In [169]: result = df.groupby(’a’).apply(compute_metrics) In In [170]: result Out[170]: metrics b_sum c_mean a 0 2 0.5 1 2 0.5 2 2 0.5 In [171]: result.stack() Out[171]: a metrics 0 b_sum 2.0 c_mean 0.5 1 b_sum 2.0 c_mean 0.5 2 b_sum 2.0 c_mean 0.5 dtype:0 码力 | 1579 页 | 9.15 MB | 1 年前3
pandas: powerful Python data analysis toolkit - 0.17.02 0 4 17.10.2 Returning a Series to propagate names Group DataFrame columns, compute a set of metrics and return a named Series. The Series name is used as the name for the column index. This is especially compute_metrics(x): .....: result = {'b_sum': x['b'].sum(), 'c_mean': x['c'].mean()} .....: return pd.Series(result, name='metrics') .....: In [172]: result = df.groupby('a').apply(compute_metrics) In Out[173]: metrics b_sum c_mean a 0 2 0.5 1 2 0.5 2 2 0.5 17.10. Examples 545 pandas: powerful Python data analysis toolkit, Release 0.17.0 In [174]: result.stack() Out[174]: a metrics 0 b_sum 20 码力 | 1787 页 | 10.76 MB | 1 年前3
pandas: powerful Python data analysis toolkit - 0.19.0788428 0.467576 Returning a Series to propagate names Group DataFrame columns, compute a set of metrics and return a named Series. The Series name is used as the name for the column index. This is especially compute_metrics(x): .....: result = {'b_sum': x['b'].sum(), 'c_mean': x['c'].mean()} .....: return pd.Series(result, name='metrics') .....: In [181]: result = df.groupby('a').apply(compute_metrics) In In [182]: result Out[182]: metrics b_sum c_mean a 0 2.0 0.5 1 2.0 0.5 2 2.0 0.5 In [183]: result.stack() Out[183]: a metrics 0 b_sum 2.0 c_mean 0.5 1 b_sum 2.0 c_mean 0.5 2 b_sum 2.0 c_mean 00 码力 | 1937 页 | 12.03 MB | 1 年前3
pandas: powerful Python data analysis toolkit - 0.19.1788428 0.467576 Returning a Series to propagate names Group DataFrame columns, compute a set of metrics and return a named Series. The Series name is used as the name for the column index. This is especially compute_metrics(x): .....: result = {'b_sum': x['b'].sum(), 'c_mean': x['c'].mean()} .....: return pd.Series(result, name='metrics') .....: In [181]: result = df.groupby('a').apply(compute_metrics) In In [182]: result Out[182]: metrics b_sum c_mean a 0 2.0 0.5 1 2.0 0.5 2 2.0 0.5 In [183]: result.stack() Out[183]: a metrics 0 b_sum 2.0 c_mean 0.5 1 b_sum 2.0 c_mean 0.5 2 b_sum 2.0 c_mean 00 码力 | 1943 页 | 12.06 MB | 1 年前3
pandas: powerful Python data analysis toolkit - 0.14.00.14.0 13.9.2 Returning a Series to propogate names Group DataFrame columns, compute a set of metrics and return a named Series. The Series name is used as the name for the column index. This is especially compute_metrics(x): .....: result = {’b_sum’: x[’b’].sum(), ’c_mean’: x[’c’].mean()} .....: return pd.Series(result, name=’metrics’) .....: In [159]: result = df.groupby(’a’).apply(compute_metrics) In In [160]: result Out[160]: metrics b_sum c_mean a 0 2 0.5 1 2 0.5 2 2 0.5 In [161]: result.stack() Out[161]: a metrics 0 b_sum 2.0 c_mean 0.5 1 b_sum 2.0 c_mean 0.5 2 b_sum 2.0 c_mean 0.5 dtype:0 码力 | 1349 页 | 7.67 MB | 1 年前3
pandas: powerful Python data analysis toolkit - 1.0.0Release 1.0.0 Returning a Series to propagate names Group DataFrame columns, compute a set of metrics and return a named Series. The Series name is used as the name for the column index. This is especially compute_metrics(x): .....: result = {'b_sum': x['b'].sum(), 'c_mean': x['c'].mean()} .....: return pd.Series(result, name='metrics') .....: In [233]: result = df.groupby('a').apply(compute_metrics) In In [234]: result Out[234]: metrics b_sum c_mean a 0 2.0 0.5 1 2.0 0.5 2 2.0 0.5 In [235]: result.stack() Out[235]: a metrics 0 b_sum 2.0 c_mean 0.5 1 b_sum 2.0 c_mean 0.5 2 b_sum 2.0 c_mean 00 码力 | 3015 页 | 10.78 MB | 1 年前3
pandas: powerful Python data analysis toolkit - 0.25.0760109 0.942941 Returning a Series to propagate names Group DataFrame columns, compute a set of metrics and return a named Series. The Series name is used as the name for the column index. This is especially 1, 0, 1, 0], .....: 'd': [0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1]}) .....: In [232]: def compute_metrics(x): (continues on next page) 702 Chapter 4. User Guide pandas: powerful Python data analysis toolkit mean()} .....: return pd.Series(result, name='metrics') .....: In [233]: result = df.groupby('a').apply(compute_metrics) In [234]: result Out[234]: metrics b_sum c_mean a 0 2.0 0.5 1 2.0 0.5 2 2.00 码力 | 2827 页 | 9.62 MB | 1 年前3
pandas: powerful Python data analysis toolkit - 0.25.1760109 0.942941 Returning a Series to propagate names Group DataFrame columns, compute a set of metrics and return a named Series. The Series name is used as the name for the column index. This is especially 1, 0, 1, 0], .....: 'd': [0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1]}) .....: In [232]: def compute_metrics(x): (continues on next page) 702 Chapter 4. User Guide pandas: powerful Python data analysis toolkit mean()} .....: return pd.Series(result, name='metrics') .....: In [233]: result = df.groupby('a').apply(compute_metrics) In [234]: result Out[234]: metrics b_sum c_mean a 0 2.0 0.5 1 2.0 0.5 2 2.00 码力 | 2833 页 | 9.65 MB | 1 年前3
pandas: powerful Python data analysis toolkit - 0.15.12 0 4 16.9.2 Returning a Series to propagate names Group DataFrame columns, compute a set of metrics and return a named Series. The Series name is used as the name for the column index. This is especially compute_metrics(x): .....: result = {’b_sum’: x[’b’].sum(), ’c_mean’: x[’c’].mean()} .....: return pd.Series(result, name=’metrics’) .....: In [167]: result = df.groupby(’a’).apply(compute_metrics) In In [168]: result Out[168]: metrics b_sum c_mean a 0 2 0.5 1 2 0.5 2 2 0.5 In [169]: result.stack() Out[169]: a metrics 0 b_sum 2.0 c_mean 0.5 450 Chapter 16. Group By: split-apply-combine pandas:0 码力 | 1557 页 | 9.10 MB | 1 年前3
共 27 条
- 1
- 2
- 3













