如何按组应用函数?

2024-01-23

我来自另一个topic https://stackoverflow.com/questions/63529481/group-by-function-with-pandas-dataset-cronbachs-alpha-with-grouped-dataset-in/63530592?noredirect=1#comment112361853_63530592这场讨论由此开始。假设我有一个来自心理学研究的 pandas 数据框架,其中有一个因子变量(国家)和一些来自李克特量表的项目。

import pandas as pd
import numpy as np
import pingouin as pg
from numpy import nan

sim_data = pd.DataFrame.from_dict({'country': {33003: 'Vietnam',
  12172: 'Macedonia',
  5192: 'Ghana',
  32511: 'Vietnam',
  7813: 'Ghana',
  21440: 'Armenia',
  32912: 'Vietnam',
  20609: 'Georgia',
  7751: 'Ghana',
  31228: 'Laos',
  36230: 'Serbia',
  32025: 'Laos',
  21758: 'Armenia',
  35730: 'Serbia',
  8444: 'Kenya',
  19946: 'Georgia',
  37532: 'Serbia',
  22926: 'Armenia',
  27204: 'Sri_Lanka',
  31959: 'Laos',
  24535: 'Sri_Lanka',
  19433: 'Georgia',
  17137: 'Ukraine',
  26103: 'Sri_Lanka',
  33878: 'Vietnam',
  39053: 'Philippines',
  33799: 'Vietnam',
  37183: 'Serbia',
  3606: 'Colombia',
  2561: 'Colombia',
  29960: 'Laos',
  32397: 'Vietnam',
  39539: 'Philippines',
  431: 'Bolivia',
  36842: 'Serbia',
  16926: 'Ukraine',
  9287: 'Kenya',
  34246: 'Vietnam',
  16277: 'Ukraine',
  34105: 'Vietnam',
  11032: 'Kenya',
  41457: 'Philippines',
  34380: 'Vietnam',
  19482: 'Georgia',
  1844: 'Bolivia',
  9552: 'Kenya',
  35437: 'Vietnam',
  29555: 'Laos',
  29993: 'Laos',
  28114: 'Yunnan',
  15: 'Bolivia',
  27712: 'Yunnan',
  12313: 'Macedonia',
  11631: 'Kenya'},
 'step_bfi1_ab_cor': {33003: 1.8333332538604736,
  12172: 1.5,
  5192: nan,
  32511: 1.4166666269302368,
  7813: nan,
  21440: 2.4166665077209473,
  32912: 1.0,
  20609: 4.0,
  7751: 0.5,
  31228: 2.25,
  36230: 2.9375,
  32025: 1.875,
  21758: 3.9166665077209473,
  35730: 2.25,
  8444: 3.5833334922790527,
  19946: 2.3333334922790527,
  37532: 4.0625,
  22926: 3.5,
  27204: 4.083333492279053,
  31959: 3.0,
  24535: 3.5,
  19433: 2.0833334922790527,
  17137: 3.25,
  26103: 1.1666666269302368,
  33878: 1.6666667461395264,
  39053: 1.75,
  33799: 0.75,
  37183: 3.375,
  3606: 4.25,
  2561: 2.8333334922790527,
  29960: 4.25,
  32397: 3.8333332538604736,
  39539: 2.5625,
  431: 3.25,
  36842: 3.8125,
  16926: 1.9166667461395264,
  9287: 2.3333334922790527,
  34246: 1.0,
  16277: 2.9166667461395264,
  34105: 1.5833333730697632,
  11032: 1.75,
  41457: 3.75,
  34380: 1.5833332538604736,
  19482: 0.9166666269302368,
  1844: 3.6666667461395264,
  9552: 2.25,
  35437: 1.0833332538604736,
  29555: 2.25,
  29993: 4.25,
  28114: 3.6666665077209473,
  15: 3.0,
  27712: 3.25,
  12313: 2.0833334922790527,
  11631: 2.5833334922790527},
 'step_bfi3_ab_cor': {33003: 3.8333332538604736,
  12172: 3.5,
  5192: nan,
  32511: 3.4166665077209473,
  7813: nan,
  21440: 3.4166665077209473,
  32912: 3.0,
  20609: 4.0,
  7751: 2.5,
  31228: 4.25,
  36230: 3.6875,
  32025: 3.875,
  21758: 3.9166665077209473,
  35730: 2.25,
  8444: 4.583333492279053,
  19946: 2.3333334922790527,
  37532: 2.5625,
  22926: 2.5,
  27204: 3.0833334922790527,
  31959: 4.0,
  24535: 2.5,
  19433: 3.0833334922790527,
  17137: 3.25,
  26103: 3.1666665077209473,
  33878: 3.6666667461395264,
  39053: 2.5,
  33799: 3.75,
  37183: 3.375,
  3606: 4.25,
  2561: 2.8333334922790527,
  29960: 3.25,
  32397: 2.8333332538604736,
  39539: 2.5625,
  431: 3.25,
  36842: 3.0625,
  16926: 3.9166667461395264,
  9287: 3.3333334922790527,
  34246: 4.0,
  16277: 1.9166667461395264,
  34105: 3.5833334922790527,
  11032: 3.75,
  41457: 2.25,
  34380: 2.5833332538604736,
  19482: 3.9166665077209473,
  1844: 2.6666667461395264,
  9552: 3.25,
  35437: 3.0833332538604736,
  29555: 2.25,
  29993: 2.25,
  28114: 3.6666665077209473,
  15: 3.0,
  27712: 2.25,
  12313: 4.083333492279053,
  11631: 3.5833334922790527},
 'step_bfi5_ab_cor': {33003: 0.8333332538604736,
  12172: 0.5,
  5192: nan,
  32511: 2.4166665077209473,
  7813: nan,
  21440: 2.4166665077209473,
  32912: 2.0,
  20609: 2.0,
  7751: 0.5,
  31228: 3.25,
  36230: 3.6875,
  32025: 1.875,
  21758: 3.9166665077209473,
  35730: 2.25,
  8444: 1.5833333730697632,
  19946: 1.3333333730697632,
  37532: 1.8125,
  22926: 1.5,
  27204: 2.0833334922790527,
  31959: 3.0,
  24535: 1.5,
  19433: 1.0833333730697632,
  17137: 2.25,
  26103: 4.166666507720947,
  33878: 1.6666667461395264,
  39053: 1.75,
  33799: 1.75,
  37183: 3.375,
  3606: 2.25,
  2561: 1.8333333730697632,
  29960: 3.25,
  32397: 1.8333332538604736,
  39539: 2.5625,
  431: 1.25,
  36842: 3.8125,
  16926: 1.9166667461395264,
  9287: 1.3333333730697632,
  34246: 3.0,
  16277: 1.9166667461395264,
  34105: 1.5833333730697632,
  11032: 2.75,
  41457: 2.25,
  34380: 2.5833332538604736,
  19482: 1.9166666269302368,
  1844: 3.6666667461395264,
  9552: 1.25,
  35437: 1.0833332538604736,
  29555: 1.25,
  29993: 3.25,
  28114: 2.6666665077209473,
  15: 2.0,
  27712: 3.25,
  12313: 1.0833333730697632,
  11631: 3.5833334922790527},
 'step_bfi6_ab_cor': {33003: 4.1666669845581055,
  12172: 1.5,
  5192: nan,
  32511: 1.5833333730697632,
  7813: nan,
  21440: 2.5833334922790527,
  32912: 4.0,
  20609: 3.0,
  7751: 1.5,
  31228: 2.75,
  36230: 2.8125,
  32025: 4.125,
  21758: 4.083333492279053,
  35730: 1.25,
  8444: 3.4166665077209473,
  19946: 2.6666665077209473,
  37532: 3.9375,
  22926: 2.5,
  27204: 2.9166665077209473,
  31959: 2.0,
  24535: 2.5,
  19433: 2.9166665077209473,
  17137: 2.75,
  26103: 0.8333333730697632,
  33878: 4.3333330154418945,
  39053: 2.5,
  33799: 4.25,
  37183: 3.125,
  3606: 2.75,
  2561: 3.1666665077209473,
  29960: 3.75,
  32397: 1.1666667461395264,
  39539: 3.9375,
  431: 1.75,
  36842: 2.6875,
  16926: 2.0833332538604736,
  9287: 2.6666665077209473,
  34246: 3.0,
  16277: 2.0833332538604736,
  34105: 2.4166665077209473,
  11032: 3.25,
  41457: 4.25,
  34380: 2.4166667461395264,
  19482: 4.083333492279053,
  1844: 3.3333332538604736,
  9552: 2.75,
  35437: 2.9166667461395264,
  29555: 1.75,
  29993: 2.75,
  28114: 3.3333334922790527,
  15: 2.0,
  27712: 1.75,
  12313: 2.9166665077209473,
  11631: 3.4166665077209473},
 'step_bfi7_ab_cor': {33003: 1.8333332538604736,
  12172: 1.5,
  5192: nan,
  32511: 1.4166666269302368,
  7813: nan,
  21440: 2.4166665077209473,
  32912: 3.0,
  20609: 2.0,
  7751: 1.5,
  31228: 3.25,
  36230: 3.6875,
  32025: 1.875,
  21758: 3.9166665077209473,
  35730: 3.75,
  8444: 2.5833334922790527,
  19946: 1.3333333730697632,
  37532: 4.0625,
  22926: 2.5,
  27204: 3.0833334922790527,
  31959: 1.0,
  24535: 1.5,
  19433: 2.0833334922790527,
  17137: 2.25,
  26103: 2.1666665077209473,
  33878: 2.6666667461395264,
  39053: 3.25,
  33799: 0.75,
  37183: 3.375,
  3606: 2.25,
  2561: 1.8333333730697632,
  29960: 2.25,
  32397: 3.8333332538604736,
  39539: 4.0625,
  431: 3.25,
  36842: 3.8125,
  16926: 1.9166667461395264,
  9287: 2.3333334922790527,
  34246: 2.0,
  16277: 2.9166667461395264,
  34105: 1.5833333730697632,
  11032: 1.75,
  41457: 3.75,
  34380: 2.5833332538604736,
  19482: 2.9166665077209473,
  1844: 1.6666667461395264,
  9552: 2.25,
  35437: 2.0833332538604736,
  29555: 2.25,
  29993: 2.25,
  28114: 3.6666665077209473,
  15: 3.0,
  27712: 1.25,
  12313: 4.083333492279053,
  11631: 3.5833334922790527},
 'step_bfi10_ab_cor': {33003: 3.8333332538604736,
  12172: 3.5,
  5192: nan,
  32511: 3.4166665077209473,
  7813: nan,
  21440: 3.4166665077209473,
  32912: 3.0,
  20609: 4.0,
  7751: 3.5,
  31228: 3.25,
  36230: 3.6875,
  32025: 1.875,
  21758: 3.9166665077209473,
  35730: 2.25,
  8444: 2.5833334922790527,
  19946: 4.333333492279053,
  37532: 2.5625,
  22926: 2.5,
  27204: 4.083333492279053,
  31959: 2.0,
  24535: 0.4999999403953552,
  19433: 3.0833334922790527,
  17137: 3.25,
  26103: 3.1666665077209473,
  33878: 2.6666667461395264,
  39053: 3.25,
  33799: 1.75,
  37183: 3.375,
  3606: 2.25,
  2561: 2.8333334922790527,
  29960: 2.25,
  32397: 1.8333332538604736,
  39539: 4.0625,
  431: 3.25,
  36842: 3.0625,
  16926: 3.9166667461395264,
  9287: 2.3333334922790527,
  34246: 4.0,
  16277: 2.9166667461395264,
  34105: 2.5833334922790527,
  11032: 3.75,
  41457: 2.25,
  34380: 3.5833332538604736,
  19482: 3.9166665077209473,
  1844: 3.6666667461395264,
  9552: 3.25,
  35437: 3.0833332538604736,
  29555: 2.25,
  29993: 2.25,
  28114: 3.6666665077209473,
  15: 3.0,
  27712: 3.25,
  12313: 2.0833334922790527,
  11631: 4.583333492279053},
 'step_bfi17_ab_cor': {33003: 2.8333332538604736,
  12172: 1.5,
  5192: nan,
  32511: 3.4166665077209473,
  7813: nan,
  21440: 1.4166666269302368,
  32912: 2.0,
  20609: 1.0,
  7751: 3.5,
  31228: 3.25,
  36230: 2.1875,
  32025: nan,
  21758: 3.9166665077209473,
  35730: 3.75,
  8444: 3.5833334922790527,
  19946: 2.3333334922790527,
  37532: 2.5625,
  22926: 2.5,
  27204: 3.0833334922790527,
  31959: 3.0,
  24535: 2.5,
  19433: 4.083333492279053,
  17137: 2.25,
  26103: 2.1666665077209473,
  33878: 2.6666667461395264,
  39053: 1.75,
  33799: 2.75,
  37183: 3.375,
  3606: 4.25,
  2561: 0.8333333730697632,
  29960: 3.25,
  32397: 1.8333332538604736,
  39539: 2.5625,
  431: 1.25,
  36842: 2.3125,
  16926: 2.9166667461395264,
  9287: 3.3333334922790527,
  34246: 2.0,
  16277: 2.9166667461395264,
  34105: 3.5833334922790527,
  11032: 2.75,
  41457: 3.75,
  34380: 2.5833332538604736,
  19482: 3.9166665077209473,
  1844: 3.6666667461395264,
  9552: 3.25,
  35437: 2.0833332538604736,
  29555: 2.25,
  29993: 2.25,
  28114: 3.6666665077209473,
  15: 3.0,
  27712: 2.25,
  12313: 3.0833334922790527,
  11631: 3.5833334922790527},
 'step_bfi19_ab_cor': {33003: 3.1666667461395264,
  12172: 1.5,
  5192: nan,
  32511: 1.5833333730697632,
  7813: nan,
  21440: 2.5833334922790527,
  32912: 2.0,
  20609: 1.0,
  7751: 1.5,
  31228: 2.75,
  36230: 2.0625,
  32025: 2.125,
  21758: 1.0833333730697632,
  35730: 4.25,
  8444: 3.4166665077209473,
  19946: 3.6666665077209473,
  37532: 0.9375,
  22926: 2.5,
  27204: 2.9166665077209473,
  31959: 3.0,
  24535: 1.5,
  19433: 2.9166665077209473,
  17137: 2.75,
  26103: 1.8333333730697632,
  33878: 3.3333332538604736,
  39053: 3.25,
  33799: 3.25,
  37183: 3.125,
  3606: 2.75,
  2561: 3.1666665077209473,
  29960: 1.75,
  32397: 3.1666667461395264,
  39539: 2.4375,
  431: 1.75,
  36842: 2.6875,
  16926: 3.0833332538604736,
  9287: 4.666666507720947,
  34246: 3.0,
  16277: 2.0833332538604736,
  34105: 3.4166665077209473,
  11032: 3.25,
  41457: 2.75,
  34380: 2.4166667461395264,
  19482: 3.0833334922790527,
  1844: 4.3333330154418945,
  9552: 2.75,
  35437: 2.9166667461395264,
  29555: 1.75,
  29993: 1.75,
  28114: 3.3333334922790527,
  15: 2.0,
  27712: 2.75,
  12313: 0.9166666269302368,
  11631: 2.4166665077209473},
 'step_bfi23_ab_cor': {33003: 1.1666667461395264,
  12172: 3.5,
  5192: nan,
  32511: 4.583333492279053,
  7813: nan,
  21440: 3.5833334922790527,
  32912: 2.0,
  20609: 4.0,
  7751: 4.5,
  31228: 2.75,
  36230: 3.5625,
  32025: nan,
  21758: 4.083333492279053,
  35730: 4.25,
  8444: 3.4166665077209473,
  19946: 3.6666665077209473,
  37532: 3.9375,
  22926: 3.5,
  27204: 2.9166665077209473,
  31959: 3.0,
  24535: 2.5,
  19433: 2.9166665077209473,
  17137: 2.75,
  26103: 3.8333334922790527,
  33878: 1.3333332538604736,
  39053: 1.75,
  33799: 2.25,
  37183: 4.625,
  3606: 2.75,
  2561: 3.1666665077209473,
  29960: 2.75,
  32397: 3.1666667461395264,
  39539: 2.4375,
  431: 3.75,
  36842: 3.4375,
  16926: 3.0833332538604736,
  9287: 1.6666666269302368,
  34246: 3.0,
  16277: 3.0833332538604736,
  34105: 1.4166666269302368,
  11032: 4.25,
  41457: 2.75,
  34380: 2.4166667461395264,
  19482: 4.083333492279053,
  1844: 3.3333332538604736,
  9552: 3.75,
  35437: 1.9166667461395264,
  29555: 2.75,
  29993: 2.75,
  28114: 3.3333334922790527,
  15: 4.0,
  27712: 2.75,
  12313: 2.9166665077209473,
  11631: 3.4166665077209473},
 'step_bfi30_ab_cor': {33003: 1.8333332538604736,
  12172: 3.5,
  5192: nan,
  32511: 2.4166665077209473,
  7813: nan,
  21440: 3.4166665077209473,
  32912: 4.0,
  20609: 4.0,
  7751: 3.5,
  31228: 3.25,
  36230: 3.6875,
  32025: 1.875,
  21758: 3.9166665077209473,
  35730: 2.25,
  8444: 2.5833334922790527,
  19946: 4.333333492279053,
  37532: 4.0625,
  22926: 3.5,
  27204: 4.083333492279053,
  31959: 4.0,
  24535: 3.5,
  19433: 4.083333492279053,
  17137: 3.25,
  26103: 3.1666665077209473,
  33878: 3.6666667461395264,
  39053: 1.0,
  33799: 0.75,
  37183: 3.375,
  3606: 4.25,
  2561: 2.8333334922790527,
  29960: 3.25,
  32397: 2.8333332538604736,
  39539: 4.0625,
  431: 3.25,
  36842: 3.8125,
  16926: 2.9166667461395264,
  9287: 2.3333334922790527,
  34246: 3.0,
  16277: 2.9166667461395264,
  34105: 2.5833334922790527,
  11032: 3.75,
  41457: 3.75,
  34380: 3.5833332538604736,
  19482: 3.9166665077209473,
  1844: 3.6666667461395264,
  9552: 2.25,
  35437: 3.0833332538604736,
  29555: 2.25,
  29993: 3.25,
  28114: 3.6666665077209473,
  15: 1.0,
  27712: 3.25,
  12313: 4.083333492279053,
  11631: 4.583333492279053},
 'step_bfi32_ab_cor': {33003: 3.8333332538604736,
  12172: 1.5,
  5192: nan,
  32511: 3.4166665077209473,
  7813: nan,
  21440: 3.4166665077209473,
  32912: 4.0,
  20609: 4.0,
  7751: 3.5,
  31228: 3.25,
  36230: 2.9375,
  32025: 2.875,
  21758: 3.9166665077209473,
  35730: 2.25,
  8444: 3.5833334922790527,
  19946: 4.333333492279053,
  37532: 3.3125,
  22926: 3.5,
  27204: 4.083333492279053,
  31959: 3.0,
  24535: 2.5,
  19433: 4.083333492279053,
  17137: 3.25,
  26103: 3.1666665077209473,
  33878: 3.6666667461395264,
  39053: 1.75,
  33799: 3.75,
  37183: 1.875,
  3606: 4.25,
  2561: 2.8333334922790527,
  29960: 3.25,
  32397: 2.8333332538604736,
  39539: 2.5625,
  431: 3.25,
  36842: 3.0625,
  16926: 2.9166667461395264,
  9287: 2.3333334922790527,
  34246: 4.0,
  16277: 2.9166667461395264,
  34105: 3.5833334922790527,
  11032: 3.75,
  41457: 2.25,
  34380: 2.5833332538604736,
  19482: 3.9166665077209473,
  1844: 3.6666667461395264,
  9552: 3.25,
  35437: 3.0833332538604736,
  29555: 3.25,
  29993: 3.25,
  28114: 3.6666665077209473,
  15: 3.0,
  27712: 2.25,
  12313: 3.0833334922790527,
  11631: 3.5833334922790527},
 'step_bfi33_ab_cor': {33003: 1.8333332538604736,
  12172: 3.5,
  5192: nan,
  32511: 3.4166665077209473,
  7813: nan,
  21440: 2.4166665077209473,
  32912: 4.0,
  20609: 2.0,
  7751: 3.5,
  31228: 3.25,
  36230: 2.9375,
  32025: 3.875,
  21758: 3.9166665077209473,
  35730: 3.75,
  8444: 3.5833334922790527,
  19946: 4.333333492279053,
  37532: 4.0625,
  22926: 2.5,
  27204: 3.0833334922790527,
  31959: 2.0,
  24535: 1.5,
  19433: 2.0833334922790527,
  17137: 1.25,
  26103: 3.1666665077209473,
  33878: 3.6666667461395264,
  39053: 2.5,
  33799: 3.75,
  37183: 3.375,
  3606: 2.25,
  2561: 2.8333334922790527,
  29960: 3.25,
  32397: 2.8333332538604736,
  39539: 3.3125,
  431: 2.25,
  36842: 3.0625,
  16926: 2.9166667461395264,
  9287: 3.3333334922790527,
  34246: 3.0,
  16277: 2.9166667461395264,
  34105: 3.5833334922790527,
  11032: 3.75,
  41457: 3.75,
  34380: 3.5833332538604736,
  19482: 3.9166665077209473,
  1844: 3.6666667461395264,
  9552: 2.25,
  35437: 3.0833332538604736,
  29555: 3.25,
  29993: 2.25,
  28114: 3.6666665077209473,
  15: 3.0,
  27712: 1.25,
  12313: 3.0833334922790527,
  11631: 3.5833334922790527},
 'step_bfi34_ab_cor': {33003: 3.8333332538604736,
  12172: 1.5,
  5192: nan,
  32511: 3.4166665077209473,
  7813: nan,
  21440: 3.4166665077209473,
  32912: 3.0,
  20609: 1.0,
  7751: 3.5,
  31228: 2.25,
  36230: 2.9375,
  32025: nan,
  21758: 3.9166665077209473,
  35730: 3.75,
  8444: 2.5833334922790527,
  19946: 3.3333334922790527,
  37532: 2.5625,
  22926: 2.5,
  27204: 2.0833334922790527,
  31959: 2.0,
  24535: 1.5,
  19433: 3.0833334922790527,
  17137: 3.25,
  26103: 2.1666665077209473,
  33878: 2.6666667461395264,
  39053: 2.5,
  33799: 3.75,
  37183: 3.375,
  3606: 1.25,
  2561: 3.8333334922790527,
  29960: 2.25,
  32397: 1.8333332538604736,
  39539: 2.5625,
  431: 2.25,
  36842: 2.3125,
  16926: 2.9166667461395264,
  9287: 3.3333334922790527,
  34246: 4.0,
  16277: 2.9166667461395264,
  34105: 1.5833333730697632,
  11032: 3.75,
  41457: 2.25,
  34380: 1.5833332538604736,
  19482: 3.9166665077209473,
  1844: 3.6666667461395264,
  9552: 3.25,
  35437: 3.0833332538604736,
  29555: 2.25,
  29993: 2.25,
  28114: 2.6666665077209473,
  15: 3.0,
  27712: 2.25,
  12313: 1.0833333730697632,
  11631: 2.5833334922790527},
 'step_bfi36_ab_cor': {33003: 2.8333332538604736,
  12172: 3.5,
  5192: nan,
  32511: 3.4166665077209473,
  7813: nan,
  21440: 2.4166665077209473,
  32912: 3.0,
  20609: 4.0,
  7751: 2.5,
  31228: 3.25,
  36230: 3.6875,
  32025: 1.875,
  21758: 1.9166666269302368,
  35730: 2.25,
  8444: 3.5833334922790527,
  19946: 4.333333492279053,
  37532: 3.3125,
  22926: 3.5,
  27204: 3.0833334922790527,
  31959: 3.0,
  24535: 2.5,
  19433: 4.083333492279053,
  17137: 2.25,
  26103: 2.1666665077209473,
  33878: 3.6666667461395264,
  39053: 3.25,
  33799: 3.75,
  37183: 3.375,
  3606: 4.25,
  2561: 2.8333334922790527,
  29960: 3.25,
  32397: 1.8333332538604736,
  39539: 2.5625,
  431: 2.25,
  36842: 3.0625,
  16926: 1.9166667461395264,
  9287: 0.3333333730697632,
  34246: 2.0,
  16277: 2.9166667461395264,
  34105: 3.5833334922790527,
  11032: 3.75,
  41457: 3.75,
  34380: 3.5833332538604736,
  19482: 3.9166665077209473,
  1844: 3.6666667461395264,
  9552: 3.25,
  35437: 3.0833332538604736,
  29555: 1.25,
  29993: 2.25,
  28114: 3.6666665077209473,
  15: 3.0,
  27712: 3.25,
  12313: 4.083333492279053,
  11631: 3.5833334922790527},
 'step_bfi39_ab_cor': {33003: 4.1666669845581055,
  12172: 3.5,
  5192: nan,
  32511: 4.583333492279053,
  7813: nan,
  21440: 2.5833334922790527,
  32912: 3.0,
  20609: 1.0,
  7751: 2.5,
  31228: 3.75,
  36230: 4.3125,
  32025: 1.125,
  21758: 4.083333492279053,
  35730: 2.75,
  8444: 3.4166665077209473,
  19946: 3.6666665077209473,
  37532: 2.4375,
  22926: 2.5,
  27204: 2.9166665077209473,
  31959: 3.0,
  24535: 1.5,
  19433: 2.9166665077209473,
  17137: 2.75,
  26103: 2.8333334922790527,
  33878: 3.3333332538604736,
  39053: 3.25,
  33799: 3.25,
  37183: 1.625,
  3606: 3.75,
  2561: 3.1666665077209473,
  29960: 3.75,
  32397: 3.1666667461395264,
  39539: 0.9375,
  431: 2.75,
  36842: 2.6875,
  16926: 3.0833332538604736,
  9287: 2.6666665077209473,
  34246: 3.0,
  16277: 4.0833330154418945,
  34105: 4.416666507720947,
  11032: 2.25,
  41457: 1.25,
  34380: 2.4166667461395264,
  19482: 1.0833333730697632,
  1844: 3.3333332538604736,
  9552: 1.75,
  35437: 3.9166667461395264,
  29555: 2.75,
  29993: 2.75,
  28114: 3.3333334922790527,
  15: 4.0,
  27712: 2.75,
  12313: 2.9166665077209473,
  11631: 2.4166665077209473}})

我定义了一个函数来进行 Cronbach's Alpha 分析,其代码如下:

def cronbach_alpha(df):
    # 1. Transform the df into a correlation matrix
    df_corr = df.corr()
    
    # 2.1 Calculate N
    # The number of variables equals the number of columns in the df
    N = df.shape[1]
    
    # 2.2 Calculate R
    # For this, we'll loop through the columns and append every
    # relevant correlation to an array calles "r_s". Then, we'll
    # calculate the mean of "r_s"
    rs = np.array([])
    for i, col in enumerate(df_corr.columns):
        sum_ = df_corr[col][i+1:].values
        rs = np.append(sum_, rs)
    mean_r = np.mean(rs)
    
   # 3. Use the formula to calculate Cronbach's Alpha 
    cronbach_alpha = (N * mean_r) / (1 + (N - 1) * mean_r)
    return cronbach_alpha

现在我很高兴我可以使用这里命令从我的物品中获取 Cronbach's alpha:

cronbach_alpha(sim_data.drop("country",1))

然而,我想要所有国家的克朗巴赫阿尔法。我想要的结果类似于 R 的结果

正如您所看到的,它对所有项目(此数据集中的 15 个项目)运行 Cronbach's alpha,但所有分析均按每个国家/地区进行分组。我很确定它可以用 Python 完成user https://stackoverflow.com/users/1422451/parfait开始帮助我。


  • Use pandas.DataFrame.groupby https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.groupby.html and .apply https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.core.groupby.GroupBy.apply.html功能。
  • Ghana is Nan因为该国家/地区的数据框中只有 1 行有效数据。
  • 功能cronbach_alpha当提供国家/地区的数据框时,仅返回该国家/地区的 1 个值。
cron = df.groupby('country', as_index=False).apply(cronbach_alpha).rename(columns={None: 'val'})

# display(cron)
        country       val
0       Armenia  0.918237
1       Bolivia  0.751889
2      Colombia -0.800000
3       Georgia  0.238676
4         Ghana       NaN
5         Kenya  0.746892
6          Laos  0.752618
7     Macedonia -0.800000
8   Philippines  0.569964
9        Serbia -0.675291
10    Sri_Lanka  0.916891
11      Ukraine -4.929153
12      Vietnam -0.668921
13       Yunnan  0.977778

获取每个国家的描述性统计数据

df.groupby('country').describe()

[out]:
            step_bfi1_ab_cor                                                                       step_bfi3_ab_cor                                                                       step_bfi5_ab_cor                                                                       step_bfi6_ab_cor                                                                       step_bfi7_ab_cor                                                                       step_bfi10_ab_cor                                                                       step_bfi17_ab_cor                                                                       step_bfi19_ab_cor                                                                       step_bfi23_ab_cor                                                                       step_bfi30_ab_cor                                                                       step_bfi32_ab_cor                                                                       step_bfi33_ab_cor                                                                       step_bfi34_ab_cor                                                                       step_bfi36_ab_cor                                                                       step_bfi39_ab_cor                                                                      
                       count      mean       std       min       25%       50%       75%       max            count      mean       std       min       25%       50%       75%       max            count      mean       std       min       25%       50%       75%       max            count      mean       std       min       25%       50%       75%       max            count      mean       std       min       25%       50%       75%       max             count      mean       std       min       25%       50%       75%       max             count      mean       std       min       25%       50%       75%       max             count      mean       std       min       25%       50%       75%       max             count      mean       std       min       25%       50%       75%       max             count      mean       std       min       25%       50%       75%       max             count      mean       std       min       25%       50%       75%       max             count      mean       std       min       25%       50%       75%       max             count      mean       std       min       25%       50%       75%       max             count      mean       std       min       25%       50%       75%       max             count      mean       std       min       25%       50%       75%       max
country                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       
Armenia                  3.0  3.277778  0.774298  2.416667  2.958333  3.500000  3.708333  3.916667              3.0  3.277778  0.718473  2.500000  2.958333  3.416667  3.666667  3.916667              3.0  2.611111  1.220011  1.500000  1.958333  2.416667  3.166667  3.916667              3.0  3.055556  0.891056  2.500000  2.541667  2.583333  3.333333  4.083333              3.0  2.944444  0.842999  2.416667  2.458333  2.500000  3.208333  3.916667               3.0  3.277778  0.718473  2.500000  2.958333  3.416667  3.666667  3.916667               3.0  2.611111  1.253698  1.416667  1.958333  2.500000  3.208333  3.916667               3.0  2.055556  0.843000  1.083333  1.791667  2.500000  2.541667  2.583333               3.0  3.722222  0.315495  3.500000  3.541667  3.583333  3.833333  4.083333               3.0  3.611111  0.267879  3.416667  3.458333  3.500000  3.708333  3.916667               3.0  3.611111  0.267879  3.416667  3.458333  3.500000  3.708333  3.916667               3.0  2.944444  0.842999  2.416667  2.458333  2.500000  3.208333  3.916667               3.0  3.277778  0.718473  2.500000  2.958333  3.416667  3.666667  3.916667               3.0  2.611111  0.809378  1.916667  2.166667  2.416667  2.958333  3.500000               3.0  3.055556  0.891056  2.500000  2.541667  2.583333  3.333333  4.083333
Bolivia                  3.0  3.305556  0.336788  3.000000  3.125000  3.250000  3.458333  3.666667              3.0  2.972222  0.292657  2.666667  2.833333  3.000000  3.125000  3.250000              3.0  2.305556  1.236969  1.250000  1.625000  2.000000  2.833333  3.666667              3.0  2.361111  0.851197  1.750000  1.875000  2.000000  2.666667  3.333333              3.0  2.638889  0.851197  1.666667  2.333333  3.000000  3.125000  3.250000               3.0  3.305556  0.336788  3.000000  3.125000  3.250000  3.458333  3.666667               3.0  2.638889  1.248147  1.250000  2.125000  3.000000  3.333333  3.666667               3.0  2.694444  1.424813  1.750000  1.875000  2.000000  3.166667  4.333333               3.0  3.694444  0.336788  3.333333  3.541667  3.750000  3.875000  4.000000               3.0  2.638889  1.434528  1.000000  2.125000  3.250000  3.458333  3.666667               3.0  3.305556  0.336788  3.000000  3.125000  3.250000  3.458333  3.666667               3.0  2.972222  0.708742  2.250000  2.625000  3.000000  3.333333  3.666667               3.0  2.972222  0.708742  2.250000  2.625000  3.000000  3.333333  3.666667               3.0  2.972222  0.708742  2.250000  2.625000  3.000000  3.333333  3.666667               3.0  3.361111  0.625463  2.750000  3.041667  3.333333  3.666667  4.000000
Colombia                 2.0  3.541667  1.001734  2.833333  3.187500  3.541667  3.895833  4.250000              2.0  3.541667  1.001734  2.833333  3.187500  3.541667  3.895833  4.250000              2.0  2.041667  0.294628  1.833333  1.937500  2.041667  2.145833  2.250000              2.0  2.958333  0.294628  2.750000  2.854167  2.958333  3.062500  3.166667              2.0  2.041667  0.294628  1.833333  1.937500  2.041667  2.145833  2.250000               2.0  2.541667  0.412479  2.250000  2.395833  2.541667  2.687500  2.833333               2.0  2.541667  2.415948  0.833333  1.687500  2.541667  3.395833  4.250000               2.0  2.958333  0.294628  2.750000  2.854167  2.958333  3.062500  3.166667               2.0  2.958333  0.294628  2.750000  2.854167  2.958333  3.062500  3.166667               2.0  3.541667  1.001734  2.833333  3.187500  3.541667  3.895833  4.250000               2.0  3.541667  1.001734  2.833333  3.187500  3.541667  3.895833  4.250000               2.0  2.541667  0.412479  2.250000  2.395833  2.541667  2.687500  2.833333               2.0  2.541667  1.826693  1.250000  1.895833  2.541667  3.187500  3.833333               2.0  3.541667  1.001734  2.833333  3.187500  3.541667  3.895833  4.250000               2.0  3.458333  0.412479  3.166667  3.312500  3.458333  3.604167  3.750000
Georgia                  4.0  2.333333  1.271118  0.916667  1.791667  2.208333  2.750000  4.000000              4.0  3.333333  0.784691  2.333333  2.895833  3.500000  3.937500  4.000000              4.0  1.583333  0.446177  1.083333  1.270833  1.625000  1.937500  2.000000              4.0  3.166667  0.627311  2.666667  2.854167  2.958333  3.270833  4.083333              4.0  2.083333  0.649073  1.333333  1.833333  2.041667  2.291667  2.916667               4.0  3.833333  0.531420  3.083333  3.708333  3.958333  4.083333  4.333333               4.0  2.833333  1.454559  1.000000  2.000000  3.125000  3.958333  4.083333               4.0  2.666667  1.156703  1.000000  2.437500  3.000000  3.229167  3.666667               4.0  3.666667  0.531420  2.916667  3.479167  3.833333  4.020833  4.083333               4.0  4.083333  0.180021  3.916667  3.979167  4.041667  4.145833  4.333333               4.0  4.083333  0.180021  3.916667  3.979167  4.041667  4.145833  4.333333               4.0  3.083333  1.215258  2.000000  2.062500  3.000000  4.020833  4.333333               4.0  2.833333  1.271118  1.000000  2.562500  3.208333  3.479167  3.916667               4.0  4.083333  0.180021  3.916667  3.979167  4.041667  4.145833  4.333333               4.0  2.166667  1.335068  1.000000  1.062500  2.000000  3.104167  3.666667
Ghana                    1.0  0.500000       NaN  0.500000  0.500000  0.500000  0.500000  0.500000              1.0  2.500000       NaN  2.500000  2.500000  2.500000  2.500000  2.500000              1.0  0.500000       NaN  0.500000  0.500000  0.500000  0.500000  0.500000              1.0  1.500000       NaN  1.500000  1.500000  1.500000  1.500000  1.500000              1.0  1.500000       NaN  1.500000  1.500000  1.500000  1.500000  1.500000               1.0  3.500000       NaN  3.500000  3.500000  3.500000  3.500000  3.500000               1.0  3.500000       NaN  3.500000  3.500000  3.500000  3.500000  3.500000               1.0  1.500000       NaN  1.500000  1.500000  1.500000  1.500000  1.500000               1.0  4.500000       NaN  4.500000  4.500000  4.500000  4.500000  4.500000               1.0  3.500000       NaN  3.500000  3.500000  3.500000  3.500000  3.500000               1.0  3.500000       NaN  3.500000  3.500000  3.500000  3.500000  3.500000               1.0  3.500000       NaN  3.500000  3.500000  3.500000  3.500000  3.500000               1.0  3.500000       NaN  3.500000  3.500000  3.500000  3.500000  3.500000               1.0  2.500000       NaN  2.500000  2.500000  2.500000  2.500000  2.500000               1.0  2.500000       NaN  2.500000  2.500000  2.500000  2.500000  2.500000
Kenya                    5.0  2.500000  0.677003  1.750000  2.250000  2.333333  2.583333  3.583333              5.0  3.700000  0.532291  3.250000  3.333333  3.583333  3.750000  4.583333              5.0  2.100000  1.024695  1.250000  1.333333  1.583333  2.750000  3.583333              5.0  3.100000  0.365148  2.666667  2.750000  3.250000  3.416667  3.416667              5.0  2.500000  0.677003  1.750000  2.250000  2.333333  2.583333  3.583333               5.0  3.300000  0.908295  2.333333  2.583333  3.250000  3.750000  4.583333               5.0  3.300000  0.341565  2.750000  3.250000  3.333333  3.583333  3.583333               5.0  3.300000  0.861201  2.416667  2.750000  3.250000  3.416667  4.666667               5.0  3.300000  0.974679  1.666667  3.416667  3.416667  3.750000  4.250000               5.0  3.100000  1.024695  2.250000  2.333333  2.583333  3.750000  4.583333               5.0  3.300000  0.570088  2.333333  3.250000  3.583333  3.583333  3.750000               5.0  3.300000  0.605530  2.250000  3.333333  3.583333  3.583333  3.750000               5.0  3.100000  0.508265  2.583333  2.583333  3.250000  3.333333  3.750000               5.0  2.900000  1.446260  0.333333  3.250000  3.583333  3.583333  3.750000               5.0  2.500000  0.612372  1.750000  2.250000  2.416667  2.666667  3.416667
Laos                     6.0  2.979167  1.050050  1.875000  2.250000  2.625000  3.937500  4.250000              6.0  3.312500  0.886531  2.250000  2.500000  3.562500  3.968750  4.250000              6.0  2.645833  0.867528  1.250000  2.156250  3.125000  3.250000  3.250000              6.0  2.854167  0.936805  1.750000  2.187500  2.750000  3.500000  4.125000              6.0  2.145833  0.726364  1.000000  1.968750  2.250000  2.250000  3.250000               6.0  2.312500  0.485734  1.875000  2.062500  2.250000  2.250000  3.250000               5.0  2.800000  0.512348  2.250000  2.250000  3.000000  3.250000  3.250000               6.0  2.187500  0.557618  1.750000  1.750000  1.937500  2.593750  3.000000               5.0  2.800000  0.111803  2.750000  2.750000  2.750000  2.750000  3.000000               6.0  2.979167  0.776276  1.875000  2.500000  3.250000  3.250000  4.000000               6.0  3.145833  0.166145  2.875000  3.062500  3.250000  3.250000  3.250000               6.0  2.979167  0.708946  2.000000  2.500000  3.250000  3.250000  3.875000               5.0  2.200000  0.111803  2.000000  2.250000  2.250000  2.250000  2.250000               6.0  2.479167  0.823167  1.250000  1.968750  2.625000  3.187500  3.250000               6.0  2.854167  0.963122  1.125000  2.750000  2.875000  3.562500  3.750000
Macedonia                2.0  1.791667  0.412479  1.500000  1.645833  1.791667  1.937500  2.083333              2.0  3.791667  0.412479  3.500000  3.645833  3.791667  3.937500  4.083333              2.0  0.791667  0.412479  0.500000  0.645833  0.791667  0.937500  1.083333              2.0  2.208333  1.001734  1.500000  1.854167  2.208333  2.562500  2.916667              2.0  2.791667  1.826693  1.500000  2.145833  2.791667  3.437500  4.083333               2.0  2.791667  1.001734  2.083333  2.437500  2.791667  3.145833  3.500000               2.0  2.291667  1.119586  1.500000  1.895833  2.291667  2.687500  3.083333               2.0  1.208333  0.412479  0.916667  1.062500  1.208333  1.354167  1.500000               2.0  3.208333  0.412479  2.916667  3.062500  3.208333  3.354167  3.500000               2.0  3.791667  0.412479  3.500000  3.645833  3.791667  3.937500  4.083333               2.0  2.291667  1.119586  1.500000  1.895833  2.291667  2.687500  3.083333               2.0  3.291667  0.294628  3.083333  3.187500  3.291667  3.395833  3.500000               2.0  1.291667  0.294628  1.083333  1.187500  1.291667  1.395833  1.500000               2.0  3.791667  0.412479  3.500000  3.645833  3.791667  3.937500  4.083333               2.0  3.208333  0.412479  2.916667  3.062500  3.208333  3.354167  3.500000
Philippines              3.0  2.687500  1.005842  1.750000  2.156250  2.562500  3.156250  3.750000              3.0  2.437500  0.165359  2.250000  2.375000  2.500000  2.531250  2.562500              3.0  2.187500  0.409840  1.750000  2.000000  2.250000  2.406250  2.562500              3.0  3.562500  0.933324  2.500000  3.218750  3.937500  4.093750  4.250000              3.0  3.687500  0.409840  3.250000  3.500000  3.750000  3.906250  4.062500               3.0  3.187500  0.907865  2.250000  2.750000  3.250000  3.656250  4.062500               3.0  2.687500  1.005842  1.750000  2.156250  2.562500  3.156250  3.750000               3.0  2.812500  0.409840  2.437500  2.593750  2.750000  3.000000  3.250000               3.0  2.312500  0.511585  1.750000  2.093750  2.437500  2.593750  2.750000               3.0  2.937500  1.685184  1.000000  2.375000  3.750000  3.906250  4.062500               3.0  2.187500  0.409840  1.750000  2.000000  2.250000  2.406250  2.562500               3.0  3.187500  0.634306  2.500000  2.906250  3.312500  3.531250  3.750000               3.0  2.437500  0.165359  2.250000  2.375000  2.500000  2.531250  2.562500               3.0  3.187500  0.596212  2.562500  2.906250  3.250000  3.500000  3.750000               3.0  1.812500  1.254679  0.937500  1.093750  1.250000  2.250000  3.250000
Serbia                   5.0  3.287500  0.721598  2.250000  2.937500  3.375000  3.812500  4.062500              5.0  2.987500  0.585302  2.250000  2.562500  3.062500  3.375000  3.687500              5.0  2.987500  0.900738  1.812500  2.250000  3.375000  3.687500  3.812500              5.0  2.762500  0.975681  1.250000  2.687500  2.812500  3.125000  3.937500              5.0  3.737500  0.247645  3.375000  3.687500  3.750000  3.812500  4.062500               5.0  2.987500  0.585302  2.250000  2.562500  3.062500  3.375000  3.687500               5.0  2.837500  0.688352  2.187500  2.312500  2.562500  3.375000  3.750000               5.0  2.612500  1.230631  0.937500  2.062500  2.687500  3.125000  4.250000               5.0  3.962500  0.489339  3.437500  3.562500  3.937500  4.250000  4.625000               5.0  3.437500  0.708487  2.250000  3.375000  3.687500  3.812500  4.062500               5.0  2.687500  0.601106  1.875000  2.250000  2.937500  3.062500  3.312500               5.0  3.437500  0.469791  2.937500  3.062500  3.375000  3.750000  4.062500               5.0  2.987500  0.585302  2.312500  2.562500  2.937500  3.375000  3.750000               5.0  3.137500  0.543786  2.250000  3.062500  3.312500  3.375000  3.687500               5.0  2.762500  0.975681  1.625000  2.437500  2.687500  2.750000  4.312500
Sri_Lanka                3.0  2.916667  1.543355  1.166667  2.333333  3.500000  3.791667  4.083333              3.0  2.916667  0.363242  2.500000  2.791667  3.083333  3.125000  3.166667              3.0  2.583333  1.401884  1.500000  1.791667  2.083333  3.125000  4.166667              3.0  2.083333  1.102396  0.833333  1.666667  2.500000  2.708333  2.916667              3.0  2.250000  0.794949  1.500000  1.833333  2.166667  2.625000  3.083333               3.0  2.583333  1.861526  0.500000  1.833333  3.166667  3.625000  4.083333               3.0  2.583333  0.463981  2.166667  2.333333  2.500000  2.791667  3.083333               3.0  2.083333  0.740683  1.500000  1.666667  1.833333  2.375000  2.916667               3.0  3.083333  0.682113  2.500000  2.708333  2.916667  3.375000  3.833333               3.0  3.583333  0.463981  3.166667  3.333333  3.500000  3.791667  4.083333               3.0  3.250000  0.794949  2.500000  2.833333  3.166667  3.625000  4.083333               3.0  2.583333  0.939119  1.500000  2.291667  3.083333  3.125000  3.166667               3.0  1.916667  0.363242  1.500000  1.791667  2.083333  2.125000  2.166667               3.0  2.583333  0.463981  2.166667  2.333333  2.500000  2.791667  3.083333               3.0  2.416667  0.794949  1.500000  2.166667  2.833333  2.875000  2.916667
Ukraine                  3.0  2.694444  0.693889  1.916667  2.416667  2.916667  3.083333  3.250000              3.0  3.027778  1.018350  1.916667  2.583333  3.250000  3.583333  3.916667              3.0  2.027778  0.192450  1.916667  1.916667  1.916667  2.083333  2.250000              3.0  2.305556  0.384900  2.083333  2.083333  2.083333  2.416667  2.750000              3.0  2.361111  0.509175  1.916667  2.083333  2.250000  2.583333  2.916667               3.0  3.361111  0.509175  2.916667  3.083333  3.250000  3.583333  3.916667               3.0  2.694444  0.384900  2.250000  2.583333  2.916667  2.916667  2.916667               3.0  2.638889  0.509175  2.083333  2.416667  2.750000  2.916667  3.083333               3.0  2.972222  0.192450  2.750000  2.916667  3.083333  3.083333  3.083333               3.0  3.027778  0.192450  2.916667  2.916667  2.916667  3.083333  3.250000               3.0  3.027778  0.192450  2.916667  2.916667  2.916667  3.083333  3.250000               3.0  2.361111  0.962250  1.250000  2.083333  2.916667  2.916667  2.916667               3.0  3.027778  0.192450  2.916667  2.916667  2.916667  3.083333  3.250000               3.0  2.361111  0.509175  1.916667  2.083333  2.250000  2.583333  2.916667               3.0  3.305555  0.693889  2.750000  2.916667  3.083333  3.583333  4.083333
Vietnam                 10.0  1.575000  0.868206  0.750000  1.020833  1.500000  1.645833  3.833333             10.0  3.375000  0.473446  2.583333  3.020833  3.500000  3.729167  4.000000             10.0  1.875000  0.661146  0.833333  1.604167  1.791667  2.312500  3.000000             10.0  3.025000  1.142643  1.166667  2.416667  2.958333  4.125000  4.333333             10.0  2.175000  0.878806  0.750000  1.645833  2.041667  2.645833  3.833333              10.0  2.975000  0.775841  1.750000  2.604167  3.041667  3.541667  4.000000              10.0  2.575000  0.604063  1.833333  2.020833  2.625000  2.812500  3.583333              10.0  2.825000  0.619201  1.583333  2.541667  3.083333  3.229167  3.416667              10.0  2.325000  1.038198  1.166667  1.541667  2.125000  2.854167  4.583333              10.0  2.775000  0.957467  0.750000  2.458333  2.916667  3.458333  4.000000              10.0  3.475000  0.490732  2.583333  3.166667  3.625000  3.812500  4.000000              10.0  3.275000  0.623671  1.833333  3.020833  3.500000  3.645833  4.000000              10.0  2.875000  0.929000  1.583333  2.041667  3.041667  3.666667  4.000000              10.0  3.075000  0.683187  1.833333  2.875000  3.250000  3.583333  3.750000              10.0  3.525000  0.707161  2.416667  3.041667  3.291667  4.104167  4.583333
Yunnan                   2.0  3.458333  0.294628  3.250000  3.354167  3.458333  3.562500  3.666667              2.0  2.958333  1.001734  2.250000  2.604167  2.958333  3.312500  3.666667              2.0  2.958333  0.412479  2.666667  2.812500  2.958333  3.104167  3.250000              2.0  2.541667  1.119586  1.750000  2.145833  2.541667  2.937500  3.333333              2.0  2.458333  1.708841  1.250000  1.854167  2.458333  3.062500  3.666667               2.0  3.458333  0.294628  3.250000  3.354167  3.458333  3.562500  3.666667               2.0  2.958333  1.001734  2.250000  2.604167  2.958333  3.312500  3.666667               2.0  3.041667  0.412479  2.750000  2.895833  3.041667  3.187500  3.333333               2.0  3.041667  0.412479  2.750000  2.895833  3.041667  3.187500  3.333333               2.0  3.458333  0.294628  3.250000  3.354167  3.458333  3.562500  3.666667               2.0  2.958333  1.001734  2.250000  2.604167  2.958333  3.312500  3.666667               2.0  2.458333  1.708841  1.250000  1.854167  2.458333  3.062500  3.666667               2.0  2.458333  0.294628  2.250000  2.354167  2.458333  2.562500  2.666667               2.0  3.458333  0.294628  3.250000  3.354167  3.458333  3.562500  3.666667               2.0  3.041667  0.412479  2.750000  2.895833  3.041667  3.187500  3.333333
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何按组应用函数? 的相关文章

随机推荐

  • 类型注释被推断的表达式类型覆盖

    在 Scala 编程语言中 假设我将使用更广泛的类型注释表达式并提供一个狭窄的值 我的程序将被拒绝 scala gt def x A A 8
  • 使用 HTML 和 CSS 剪辑图像

    我想在 144px x 144px div 元素中显示图像 图像总是大于 144px 所以我想缩放它们 我的意思是最小的一侧将接触 div 的边缘 从另一侧 与信箱相反 切掉一点 我怎样才能做到这一点并让它在 IE 等旧版浏览器上也能工作
  • 在 NodeJS Lambda 函数中列出 AWS.CognitoIdentityServiceProvider.listUsers 中的用户及其组?

    因此 我需要在客户端的自定义管理屏幕中显示用户列表及其各个组 我正在返回结果AWS CognitoIdentityServiceProvider listUsers在 Lambda 函数中 这可以很好地列出用户 但我不确定为每个用户获取组并
  • 按行名称连接多个表[重复]

    这个问题在这里已经有答案了 我想按行名称合并多个表 这些表的行数不同 并且它们具有唯一行和共享行 这些行都应该出现在输出中 如果可能的话我想解决这个问题awk 但我也对其他解决方案感到满意 表1 tab a 5 b 5 d 9 表2 tab
  • C++:成员指针已初始化?

    代码示例应该解释一下 class A B pB C pC D d public A int i int j d j pC new C i abc note pB is not initialised e g pB NULL 显然 pB 应该
  • C++ 11 线程与 clang

    我想学习使用 C 11 线程来加速我的语言的编译 是的 我正在构建一个编译器 x 我尝试的第一个示例在 clang 3 3 SVN 中抛出了几个错误 它在 GCC 4 6 3 下编译得很好 我从 llvm org 的 SVN 下载了 cla
  • 将对象的子集直接解构为新对象[重复]

    这个问题在这里已经有答案了 有没有一条语句可以做到这一点 我正在空白 this state is a basic object with many keys var toDate fromDate location flavor this
  • 无法更新 FBSDKCoreKit POD iOS

    当我尝试进行 pod 更新时 出现以下错误 一旦失败 我什至无法再进行 pod install 了 安装FBSDKCoreKit 4 36 0 安装 FBSDKCoreKit 时出错 usr bin git 克隆https github c
  • Visual C++ 中的堆框架有多大

    在 Visual C 中 如果我使用 new 在堆上创建对象 堆帧头和填充会占用多少额外空间 特别是在发布代码中 我期望一个 int 表示块中有多少可用空间 另一个可能表示当前正在使用多少空间 并且帧大小根据体系结构四舍五入到最接近的 32
  • WEB API 返回遵循序列化属性的对象

    我正在使用 WEB API 返回一个对象 类 类已经使用 System Xml Serialization 属性进行结构化 这使得使用 WEB API 返回整个类变得困难 因为它公开的内容超出了应有的范围 我不认为这是序列化类并返回字符串的
  • MDX 查询返回记录数

    以下是我的 MDX 查询 SELECT NON EMPTY Measures Fact Sample Count ON COLUMNS NON EMPTY Fact Sample Sample Reference No Sample Ref
  • Django 的缓存模块可以在 Google App Engine 上运行吗?

    我正在 Google App Engine 上运行 Django 1 0 2 并且想知道以下哪一项 如果有 Django 缓存模块 http docs djangoproject com en dev topics cache 本质上应该与
  • GCC 生成的 ARM 和 x86 汇编代码的差异

    让我们看一个简单的 C 代码来设置寄存器 int main int a int 111111 a 0x1000 return 0 当我使用 1 级优化为 ARM arm none eabi gcc 编译此代码时 汇编代码类似于 mov r2
  • travis 构建失败,因为缺少 devtools

    我正在尝试设置 travis 构建 但失败并出现以下错误 export PKG TARBALL Rscript e pkg lt devtools as package cat paste0 pkg package pkg version
  • Django JavaScript 文件

    在 Django 应用程序中 我应该将 javascript jquery 脚本放在哪里 与其他静态媒体一起使用 请参阅此处了解更多信息 http docs djangoproject com en dev howto static fil
  • 使用 Margin Auto 和 Center 将 Float Left Div 居中

    我知道这个问题已经被问过很多次了 将 div 居中对齐 https stackoverflow com questions 1740587 float a div to center 不过 我遵循他们的建议
  • XNA 的 CPU 使用率高

    我今天刚刚注意到 当我编译并运行一款新的 XNA 4 0 游戏时 其中一个 CPU 线程以 100 的速度运行 并且帧速率下降到 54 FPS 奇怪的是 有时它可以在 60 FPS 下运行 但随后就会下降到 54 FPS 我以前没有注意到这
  • 在 OPTIONS 响应后使 fetch API 与 CORS 一起使用

    我正在尝试从我们的 API 获取数据 API 已启用 CORS 支持并对 OPTIONS 请求返回以下响应 Access Control Request Headers content type Access Control Allow O
  • requireJS 中的上下文和嵌套模块

    我在 requireJS 中的上下文方面遇到了一些麻烦 我想要的是在配置阶段 在加载任何模块之前 创建一个上下文 mycontext 然后始终保留该上下文 这很复杂 因为不幸的是 我需要 base js contextReq require
  • 如何按组应用函数?

    我来自另一个topic https stackoverflow com questions 63529481 group by function with pandas dataset cronbachs alpha with groupe