Pandas 数据透视表,其中一个值列由值列表组成

问题描述 投票:0回答:1

我有一个 Pandas 数据框,我希望对其进行旋转,其中包含的

values
条目之一由值列表组成。

df

    l1_ratio    mse_path    coef    intercept
0   1.0 581499561.8597653   [253.03936312711443, 3649.109906786345, 14798.282876868554, 4810.759749988098, 8878.435479294187, 3276.7488397077536, 5171.81213816377, 9059.114207547327, 11.512129682487922, -0.0, 8710.623469210213, 0.0, 0.0, -598.4862056332136, 28425.47104579133, 0.0, -0.0, 0.0, 0.0, -2198.436487334907, -2418.25205363894, 0.0, 1692.592401606466, -0.0, 390.8734205415331, 4623.261872236998, 699.2497258078156, 62.239979130074225, 0.0, -0.0, 1399.6393449513669, 912.4450426439255, 0.0, -0.0, -0.0, -0.0, -209.73967722935762, 0.0, -684.1610010188986, 162.79546249454427, 0.0, 0.0, 0.0, -0.0, 0.0, 0.0, -0.0, -0.0, 0.0, -1070.3678099420492, -0.0, 0.0, 0.0, -0.0, 0.0, -1073.2954543338647, 0.0, 0.0, -0.0, -0.0, 951.6951496704327, -0.0, 0.0, -0.0, -0.0, 580.5064483922187, -0.0, -0.0, 0.0, 0.0, -172.30638224708616, 0.0, -0.0, 176.66963320427527, -0.0, 0.0, 2101.100923369119, -0.0, -0.0, 0.0, 1899.3349417983618, -0.0, -0.0, -0.0, -0.0, -0.0, 0.0, -444.2106622645467, 4079.307030203663, 5932.224851788115, -0.0, -0.0, 0.0, -0.0, 1271.547535404467, 4589.157779146342, -0.0, -0.0, -0.0, 1546.2122719295912, 43.68350839455409, 799.1353377003892, -0.0, 0.0, -0.0, -0.0, -0.0, -0.0, 1997.1599067500804, 0.0, -0.0, -0.0, 0.0, -0.0, -139.11014781577043, -2134.548060887319, -2725.175680089511, 0.0, 0.0, -0.0, -0.0, 0.0, 0.0, -0.0, -0.0, 0.0, 762.0978139944438, -0.0, -0.0, 0.0, 0.0, -0.0, -0.0, -0.0, 2641.475746141273, 0.0, -0.0, 1665.684460419034, 0.0, 757.0523501978001, -0.0, -0.0, 0.0, -0.0, 0.0, -0.0, 0.0, 0.0, -0.0, -0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -0.0, 0.0, 0.0, -0.0, -370.42602621137394, 0.0, 0.0, 0.0, 0.0, -0.0, -0.0, -1944.4825663547163, -591.9747091248928, 0.0, 0.0, -0.0, -0.0, -1838.374401828182, -0.0, 0.0, -0.0, 0.0, -517.5891475030328, 1476.6782408902266, 0.0, 0.0, -0.0, -0.0, -5174.996138309539, 0.0, -0.0, -3801.7738352516685, -0.0, 0.0, 0.0, -0.0, -0.0, 3963.0786330603796, -266.91651148289, -1241.125779832931, 0.0, -0.0, 577.5306432786302, -0.0, 0.0, -0.0, 0.0, -0.0, 747.9365019997231, -0.0, 0.0, -0.0, -0.0, 0.0, -0.0, -0.0, -182.83255241378126, 0.0, -0.0, -0.0, -0.0, -796.6213861438707, 0.0, -0.0, -0.0, -0.0, -0.0, -162.4390369338168, -4651.940469706817, 0.0, -4659.32104928002, -0.0, -0.0, 0.0, -0.0, -0.0, -552.1105441909145, 2193.112874094114, -0.0, 370.0503349786939, -0.0, -0.0, -0.0, -0.0, -0.0, 384.7492825385162, -0.0, -0.0, 0.0, 0.0, -819.7722957127545, -0.0, 0.0, 72.38445704768583, 0.0, -0.0, -0.0, -0.0, 0.0, 0.0, -0.0, -0.0, -0.0, 0.0, -0.0, 154.7098997509337, -0.0, -0.0, 0.0, 5001.135030874798, 0.0, -0.0, -0.0, 0.0, -0.0, -0.0, 0.0, 0.0]    180401.21694528882
0   0.99    2214034038.866108   [1288.5108755365814, 1141.4002144343365, 2896.4098231445964, 0.0, 1437.726183039458, 1569.5515270912845, 1936.6841301002705, 1823.1086710815543, 0.0, 423.2345294724227, 2480.5476534169384, 2546.30937757155, 1070.7509478625852, -0.0, 2916.119955036174, 980.4527182573493, -37.378802962765505, 1735.7361484508306, 938.1229701846534, 496.3570106270763, -295.7527553007795, 1920.1478016912283, 1684.65644459793, 483.04213977421233, 2049.0920392831786, 2168.5834067751116, 1076.238008628459, 1058.7703167992531, -106.97246191967314, 18.28220317948517, 471.1157781234777, 305.10803219890505, -0.0, 25.894030212031456, -57.28144005355844, -0.0, -395.7046573315114, -175.91804876091754, -190.40676758531208, 91.17482633148427, -577.5845817859226, -0.0, -47.09497144947905, -238.17589197161303, 1026.282311618595, 0.0, 96.01760755796542, -134.44726519764308, -96.23577659089972, -258.99863026275324, -254.82049933253407, 138.28152785044944, -15.594574791548254, -53.419363210838, 630.7985756100181, -720.4901156275829, 138.85484964691793, 249.4203033082621, 20.713356956941293, -844.2025321573319, 722.4689151000729, 0.0, -310.2623401629524, -0.0, -32.915850514256306, 471.6124459129323, -62.11862211556542, 0.0, -132.17418703748717, 251.0320144432172, 0.0, -0.0, -194.78961750141593, -189.65400031255203, 20.85964176300863, 0.0, 349.09806278077383, -435.11189433379064, -142.87977206520654, 0.0, 182.79611576906126, -356.63579947995066, -0.0, -378.27264014515623, -128.9808913603312, -586.6177554814338, -44.200078058630645, -0.0, 1170.4500814296446, 1673.9783693722238, -448.6418089397299, -89.06494894229179, -331.7417791922637, -18.536617814051603, 326.5829823034383, 1060.562730511171, 255.0468131982831, 190.05497434530736, -299.47501805430954, 244.60190846218444, 284.5540364646699, 285.8681195735776, -150.32896927509282, -0.0, -4.972625039681385, 0.0, -57.65656657850986, -59.22279196361179, 556.4109422397493, 263.2936227316695, -0.0, -0.0, -0.0, -183.4560408780339, -258.9898426045801, -353.33368501106855, -34.100549991687394, -63.652247300182076, -94.30027635409674, 41.26781180294321, 0.0, 601.5146707800469, -208.4615238479576, -173.82150371664653, -992.1349156402378, -5.202445989743139, 1065.0290066847888, -0.0, 0.0, 0.0, 0.0, -0.0, 0.0, 11.183040696304912, 623.7881665925077, -0.0, -0.0, 169.81050210880974, -8.99546735793611, 496.59978201632106, -346.0610215064944, 0.0, -212.21802108495342, -107.52597574093022, 67.2604487664647, 26.18127976869913, -0.1859106121510271, 689.7833802221692, -295.7595004044681, -31.828934672723047, -0.0, -13.431770612003968, 47.34684657851442, -0.0, 456.7752948253894, -295.7097467369197, 217.75663833813476, -167.0240525154184, 13.119028988342224, -190.38680651312075, 67.26089494444646, -0.0, -0.0, 684.4056604135054, -256.26977952572673, -52.023214009686555, 547.1319773359934, -55.979446689306364, -1075.392831544414, 991.7328009993199, -289.4642763067799, 1042.614795123592, -1818.0125822592026, -316.0191242640419, -0.0, -67.50860076854983, 110.97572842589076, -1042.7942642855426, 1449.6554692979535, -202.8457512185241, 0.0, -0.0, -355.6609329403728, 55.99441520091489, -317.94628256217095, -0.0, -1235.8949254076197, -268.38614492459465, 223.77798861865043, -317.94218063833654, -19.485732547608414, 143.59190337259554, 1432.4716556753574, 0.0, -981.5310761970001, -316.65366054598894, -265.5204624571671, 1440.9518123212615, -158.70992249129722, -317.93827165503893, -356.0739471006797, -372.2717195206707, -32.76230852993284, 136.57315701079378, -35.57211729261106, -307.05951186249825, -67.39523106286269, 207.5873505271385, 70.99392538698746, -0.0, -86.92648016855802, -0.0, -74.2555658664915, -311.53928831040525, -326.07741269037325, -57.42460332942894, -991.8374742057182, 626.0598772128691, -220.31626712062035, -57.58038162029573, -0.0, 517.846849748521, -310.30485997062044, 434.4311428989644, -0.0, -1623.713494776604, -147.24790042773182, -75.08697695680965, -93.20446491616461, -0.0, -118.05622510867376, -71.83673868144035, 300.0590500084468, -87.82710434512016, 1283.226314913383, -1551.4156046961957, -134.62472833566693, 229.74025226894264, 754.9018930958974, -118.97884961404972, 696.281628642635, -173.77757446902064, -899.4327344671217, -403.98364401941393, -400.8475048015838, 56.13121758676302, -1137.1913929011605, -309.31673166928437, 297.977600702344, -400.8507800725531, -38.771944949119685, 410.98676359917056, -327.6428271259632, 0.0, -400.85996582844353, -127.83828668012485, 569.3934393329992, -96.82731711388608, 604.4531534927594, -0.0, 36.379889517416466, -135.49296057984154, -0.0, -16.196866480782283, 1182.6005299476797, -0.07870072095822686, -0.0, -603.0486105754311, -44.98469441598015, -0.0, -90.17559291390286, -379.08488477737984, 1166.8318977943532]    180401.21694528876
0   0.95    4477216372.464831   [451.90379889404005, 364.42705000899014, 1000.411275893526, -70.67834247340133, 632.9642092794054, 621.5537787066967, 649.9067608748471, 580.0671499591238, 0.0, 202.34565811997464, 838.5700412425219, 835.6333063594087, 348.49657416657107, -15.435525288027897, 944.254509860495, 338.0328035262107, -25.01372649044941, 661.1395852808022, 345.20131644220334, 187.72254522333623, -119.75812611787666, 643.8362889301778, 596.5734316125265, 265.95524492651293, 781.0370773108815, 790.8493276183372, 391.4790922420105, 392.28276353035255, -107.65109614935568, 20.49781579702922, 140.84646319735447, 89.21383666299006, -5.709537584686129, 29.585311060864015, -29.73170383999819, -0.0, -137.74419480613744, -74.7864616578633, -94.4276526086043, 53.42182824135511, -260.02253156825583, -3.7458522151629796, -57.312008847900074, -170.70164218535564, 423.50265683498435, -29.819573656467355, 17.959719899823106, -35.199059516069376, -47.36055181108414, -101.65546133033381, -117.24242369513455, 91.12970247460754, -22.045447863665522, -43.492085002480614, 275.747859012535, -323.21171444980564, 61.4614740346074, 104.45059077873566, 30.536427200632605, -347.46829255393794, 241.8145406945114, 9.571595012513287, -94.85279189868415, -0.0, -21.727340289738624, 167.20848810503156, -9.379669243490675, 2.293390540409582, -69.4319705489917, 77.0817901696514, 9.583115375013227, -16.99796142873087, -95.64615672686531, -134.88611098355096, 26.5470573144565, 58.47518976754938, 89.62417000334226, -184.33126127862616, 0.0, 0.0, 36.92843080976247, -182.7076651682731, -0.0, -142.17260147053102, -45.142641452555985, -221.00966926721514, -37.44871372877418, 0.0, 372.0792644429926, 548.3617791060332, -224.6789632670541, -60.08715245526823, -136.25308295377084, -0.0, 160.0377849358875, 324.8067483079273, 134.1284353205398, 78.3926784205144, -121.72994145046935, 102.02012998308071, 91.7780087522938, 100.93612781401833, -50.56840275081557, -0.0, -13.772377823492741, 2.3262737137240297, -40.28721848451935, -10.181637858708378, 162.0048522115716, 85.16316106820207, 0.0, -0.0, -14.594827968941022, -95.23833749612112, -101.6557586637468, -128.24070531800922, 2.3865912247025003, -62.22954884685509, -27.265771781291203, 13.471630973205269, 0.0, 248.21296970579854, -86.08221556298983, -47.016631659131995, -331.98477549895966, -28.336512986318287, 357.0072423691016, -0.0, 0.0, 3.3844109010754972, -0.0, -0.0, 0.0, 31.112787210504425, 163.34403318785365, -13.857192293882765, -0.3675636122583585, 21.627418219161214, -17.757252967995132, 153.50853753056447, -120.74206393872593, 5.768971646215191, -142.92300592382966, -38.48261718876772, 14.772021549464295, 17.395339523870867, -37.01148362726991, 363.34054735331756, -172.427907165573, -33.86090644617767, -11.588867834202748, -31.26609414221257, 10.54808040632687, -10.47614548807429, 143.0533803172757, -107.78152556098911, 71.86045484035397, -128.65693892885932, 22.60726266074622, -65.35663811891264, 14.772008169480653, -2.1381671106279065, -33.352671214565795, 359.68320546519556, -164.17572694325133, -44.20005770639454, 276.27768386643555, -16.83104754120719, -465.3536491105819, 370.7140039279059, -130.0994336258551, 502.9686606142887, -707.0334321310855, -139.74774120604772, -38.57210890679462, -32.679642302123014, 96.92020965703168, -410.92209227307313, 604.504687523593, -116.83771821052989, -0.0, -0.0, -167.49274277078953, 198.1841355349268, -163.43464615962813, -18.324381770410486, -515.845277506657, -133.82201511612627, 92.67039438417184, -163.43478011758893, -31.476151953025166, 102.38540830430046, 461.0645771866528, 17.648893806112273, -348.92765407219025, -160.14517544265917, -124.42315535269812, 544.669974828584, -85.44328433953059, -163.43499382445293, -166.9397748848065, -123.17986490991824, -24.884048060379097, 39.5717252934144, -28.936549430635935, -158.75387571515523, -36.550677313764304, 116.12393272375051, 64.17472959500047, -1.9135356231550804, -54.780463237937056, -0.6133711624965174, -49.35800394033436, -138.0279627142042, -140.3987867678661, -37.11750662219265, -394.2593248954027, 290.9257534222436, -123.85884235347251, -51.09647438406486, -13.544957174666138, 259.75807112335156, -152.5424268343465, 306.5985535957529, -1.0878182287872915, -625.5063770582592, -62.187170999213194, -44.75252670857082, -59.22084584877021, -18.939160152721886, -46.535754875386935, -21.78135924967242, 120.43404404393506, -24.616794527524767, 463.80909571266795, -588.4261765857282, -56.29597855184704, 146.729763298118, 376.64630969071925, -38.5573333649, 268.04274745482746, -70.55005887711458, -410.8781686014436, -233.3242595314783, -232.6920626430331, 139.1631402151629, -483.85895403594765, -173.3033397283782, 90.23259483058987, -232.69204558485438, -37.97159376837881, 261.53843032432206, -157.4693011412452, 1.2179972941224972, -232.69196112437277, -68.80194159149096, 295.1490306038171, -74.12074492974521, 293.5207681963812, -0.0, 14.676896684265426, -64.76785846165711, -10.632647213938986, -25.640850987244516, 441.7478730306915, -23.518055099186338, -0.0, -245.27582688053062, -47.94734530008497, -3.606409330493235, -31.07248101988179, -169.87105595144465, 437.08863958436984] 180401.21694528876
0   0.9 5295530119.621321   [251.97593564024584, 199.6252818805267, 559.4157970065792, -50.2762286812302, 369.3987053762267, 356.54031154076546, 360.38951544011144, 318.91545548846716, 0.0, 118.61147271515632, 466.3076634751436, 460.9401784466648, 192.32186554762092, -12.923216647133366, 519.7287513461932, 188.34702432552217, -15.441650383291199, 374.8995459455578, 195.6475337840008, 105.03488323836403, -70.76552829179302, 355.5664401118226, 332.96647036861344, 160.2062316550571, 443.71242163288287, 446.0840468860182, 220.40033093081306, 221.4348870270198, -68.56242469622417, 13.042105928681904, 76.17869818705489, 48.122477975635725, -5.2006843500336135, 18.434156745036734, -17.689726843055425, -0.0, -76.0629392470267, -42.977960480563205, -57.194265849729874, 33.07807632159702, -151.71882426687026, -4.363050458394881, -36.360820583438716, -105.05970152372988, 244.1870859239563, -24.59362540244982, 7.931297065737346, -18.364206952553698, -27.619171604684887, -59.52129426024859, -69.28245719128246, 56.73227471120291, -14.466181792591545, -27.29198046008644, 160.28067077967034, -188.93179365526964, 36.35542577240674, 60.62404277278584, 19.344131455046167, -199.7110229366974, 133.44124614918306, 6.104313605316847, -50.31907322398952, -0.0, -13.683349449930509, 94.16753947343864, -3.914661837804196, 3.7982681154892894, -40.92530829263081, 41.43236940829952, 6.525998928882921, -11.089112859573875, -55.659136501601985, -82.62862319263004, 16.30765906059863, 43.18385464742543, 46.42646378176672, -107.0745916322784, 3.7475566477347733, 0.0, 18.75332759099362, -108.84994516198435, -0.0, -80.4498600671448, -25.21035499384165, -125.13369434158435, -22.60145914871905, 0.6655567576831709, 204.6909069593819, 302.7953402949714, -133.77317695119248, -37.40097810431059, -77.94419734205874, 0.0, 95.55214491873977, 177.26194057295228, 79.16444052615762, 44.89782919194303, -70.57954795891733, 59.9066254845167, 50.44266404536765, 56.673619743147455, -28.10333292161411, -0.0, -9.093471914862008, 3.351470919938149, -24.940102833741957, -4.168284141514984, 87.23899723186607, 46.9199770701425, 0.0, -0.0, -10.446901497122793, -57.938063199764045, -59.52129707146652, -71.54664424671307, 9.774056674076164, -39.218334251180956, -14.467755172783718, 6.870902970549463, 0.0, 143.16691573457, -49.35295285232284, -24.744152655102297, -182.3683596724859, -19.08020301973659, 196.61567671709685, -0.0, 0.0, 2.5101603694472496, -0.0, -0.0, 0.0, 19.914000557977452, 86.29799452961046, -10.7735280294561, -3.080372367329778, 8.506164935337873, -11.741792090087765, 83.79133488869304, -66.8386639577978, 4.881679096916573, -87.30774034750957, -21.900457754537193, 7.395117682725237, 10.659533154277838, -25.137701510972327, 216.9478904524629, -104.74181555433421, -21.72488751060374, -9.037135005768699, -19.803875445642742, 5.287505865926, -8.833347141843182, 78.26693364877822, -60.095752870295904, 40.0099510253525, -79.4388893502883, 14.468818577102, -36.917842085927965, 7.395117454805569, -4.079165803408042, -23.178578195536105, 214.70844510584757, -100.46504892251885, -27.920486562921113, 162.5792694231069, -9.615195887086825, -268.3767953920419, 209.2764735946544, -76.92514347941093, 295.7369916691882, -403.1577798690914, -82.66302398394107, -27.112161648070977, -19.795104675299704, 61.130417816399415, -234.33994553963043, 348.87676164897545, -70.86957238197064, -2.270490911155394, -0.0, -98.72915770165692, 130.09785672988977, -97.75526773601291, -12.876219696788745, -297.85011958370563, -80.15061611644273, 53.25499628572116, -97.75526961339325, -20.704658886344514, 63.97074507487598, 253.32495549034326, 12.92807690136254, -195.1267191359952, -95.61666708873803, -72.82314796580661, 309.19154230685, -51.49950243694954, -97.7552742667307, -97.865512739687, -68.15529672376819, -15.388701694861002, 21.73858055535895, -18.00611251114517, -95.05972006233033, -22.213966476944826, 69.92075510560996, 41.20989103619624, -5.482872468431436, -34.04504718862672, -2.9212743556224776, -30.467420875737112, -81.37749137271904, -81.32079217675143, -23.047181857203558, -225.76496142888334, 171.76954947247322, -74.96314767246852, -32.22175342944953, -9.693536935423761, 154.2979768894359, -90.92335953187093, 187.50068831538525, -2.779782211313613, -356.20424032184957, -36.49705552850452, -27.629650311168337, -36.67877125976382, -13.71207283116544, -27.2226089246089, -12.588386918950114, 70.78067443101921, -13.295239210573113, 259.26112643749656, -332.20684523757933, -32.540184905026024, 88.60229627789839, 222.95708452889198, -21.785344895666807, 152.61655029062462, -40.82150472184441, -239.56715889111723, -141.35785403930564, -141.06369785545422, 90.62784751027456, -279.3414798697823, -104.28788574685343, 48.98274746883981, -141.06369882197117, -24.250854488884155, 159.88543062595173, -93.28019886660428, 1.2634227757717067, -141.0636996091875, -41.78406728973744, 176.68759096952232, -46.20492187953321, 174.25693248558335, -1.151617971795489, 8.832671743886184, -38.4798038844731, -7.5347037525017075, -16.508423814338375, 250.14846116755533, -15.522808743135782, -0.0, -140.4430254127462, -30.68364681227584, -4.300539489420825, -17.623436394444067, -97.99582503102106, 247.6211752017288]    180401.21694528876
0   0.8 5841959239.549489   [134.19775500504332, 105.34983711411064, 298.24859199114815, -30.138427337307657, 201.60903772081693, 192.8403492498848, 191.3221917915364, 168.58647404672152, 0.0, 65.03923595485183, 247.87382726102447, 243.86588885038506, 101.9638555707181, -8.502173275460372, 274.59174174969525, 100.41130490564063, -8.972756728045846, 201.4025173839802, 105.2885201731031, 56.157993490476876, -39.23494019052579, 188.22651980055406, 177.33129395643803, 89.04381579953215, 238.60904466578492, 238.9830138177559, 118.09868497505296, 118.80885632426357, -39.32110446395187, 7.726215082099112, 40.12385203377445, 25.430517019023142, -3.6841027773092754, 10.665100759726728, -10.048238106693484, -0.0, -40.460800263361456, -23.51816176152124, -32.14066467931564, 18.91773400164531, -82.94841114985522, -3.3041604166342533, -20.928472740317503, -59.07334561328584, 132.4939270184611, -15.75707274031772, 3.896385329455582, -9.716089422379476, -15.333091039371626, -32.88653486238259, -38.34076924631165, 32.28862757250509, -8.666941224225281, -15.73540394502983, 87.43148045021756, -103.32641976639566, 20.29360366110752, 33.2657474193707, 11.262402730789209, -108.21612228476006, 70.81337597163015, 3.7531061574300617, -26.237690820949528, -0.2697564963305331, -8.078238646312515, 50.67491101238815, -2.0111626796037485, 3.0758161954254377, -22.69892082418587, 21.86081576003769, 4.094441220584245, -6.660900126134252, -30.53469533664621, -46.40505042955501, 9.387860443787114, 26.419131865462713, 23.938064412791075, -58.53015868032509, 5.553727635395261, 0.0, 9.80925256951117, -60.25617144880243, -0.06143267326634735, -43.411406075779794, -13.726965954623113, -67.38703769628576, -12.78527160664753, 2.042540152230447, 108.35603711097683, 160.43417521935254, -73.97816087019804, -21.387334711490997, -42.306718719776896, 0.0, 53.03670984356364, 93.46630849324384, 43.64228645807663, 24.524233224638824, -38.67674695661177, 33.118019647038636, 26.915673803136457, 30.56902027473035, -15.233440429924899, -0.0, -5.571065037550382, 2.6965056261490057, -14.319418973555011, -2.0710024782947922, 45.798681292065346, 25.100687650890613, 0.0, -0.11191654800259945, -6.5491387325967, -32.61833326717106, -32.88654009885019, -38.31289183419553, 8.003771042264502, -22.49304691936769, -7.7731011699443195, 3.7447892734588644, -0.0, 77.82543173078268, -26.93480222640096, -13.044247623034982, -96.36986210283152, -11.450898890368734, 104.05031538825274, -0.2669329668491528, 0.0, 1.8464842243064044, -0.0, -0.0, 0.0, 11.62833719934292, 44.84330874270659, -6.969210292545817, -2.8118802480599427, 3.8218418670018037, -7.115802503098517, 44.35636674425629, -35.66830870199088, 3.4032149454743963, -48.950531906210905, -12.10875801953953, 4.007074209990364, 6.264555752916631, -15.033111798694927, 119.88110574385743, -58.57665040848605, -12.72115781623657, -5.9009945791586595, -11.505061298086492, 2.9572106448796456, -5.902916082826569, 41.50636596270579, -32.22659816519079, 21.591293029463962, -44.78850148935345, 8.549757870269053, -20.117760730622535, 4.007074135550812, -3.3552008417876795, -14.025671169232977, 118.63142694168714, -56.38311690161957, -16.14386102463473, 89.19294076886472, -5.524705312958239, -145.52519097514272, 112.29825332880539, -42.56517219396247, 161.99448373811038, -217.2621026645042, -45.733168414649185, -16.384642421033032, -11.334094739660085, 34.93986510765465, -126.39243041285101, 189.26518494303338, -39.71582608396147, -2.7597952883150323, -0.0, -54.392476161076026, 75.22549449405486, -54.28232783984403, -7.946703052734747, -161.67333258826844, -44.61513020387595, 29.083693384473023, -54.28232917836108, -12.276092489131623, 36.41993520456413, 133.88088376726853, 8.059512449672276, -104.18704980453235, -53.0565539660227, -40.03215631863106, 166.32561568174953, -28.853465964612734, -54.28232964430377, -53.74038773338643, -36.4181071190953, -8.940562751124657, 11.810506240363761, -10.436473832248012, -52.82504560638791, -12.686385576866389, 39.02132965234936, 23.900328776739634, -4.585345015817707, -19.488407476710762, -2.6613619170881613, -17.406383419063502, -44.9431652590183, -44.438193696785, -13.284453267225942, -122.08188428186402, 94.5230364255816, -41.940981173554626, -18.560612439636746, -6.116100398928026, 85.1524522135842, -50.4295461116148, 104.81099240919306, -2.439798555741905, -191.8657172644588, -20.290996376781393, -15.827868248234378, -20.933517522276524, -8.581907382715155, -15.202106452707177, -7.184811934679164, 39.114867570845554, -7.265585889042667, 138.2340236557468, -178.019947540464, -17.956043705531084, 49.369062517296946, 122.65363852169045, -12.015415966316262, 82.3708389174356, -22.472359255767675, -130.70422060550646, -78.82911202415569, -78.69025764659365, 52.315527006398625, -151.5841124094573, -58.02706377700307, 25.96938993790877, -78.69025660689593, -14.134550621522441, 89.49667043487959, -51.550337965745236, 1.1556466408249366, -78.69025500136955, -23.575660874248175, 97.88041546244763, -26.339403440349276, 96.1418968789176, -1.3786177067024226, 5.2285238492403545, -21.491285539529443, -4.8090883369898325, -9.741864452334086, 134.42517794466278, -9.266508289223758, -0.07170959802954245, -76.03373457981506, -17.81138263975082, -3.3169984671064126, -9.794420907271167, -53.3139007143992, 133.10136874421642]  180401.21694528876
0   0.75    5965993746.00419    [108.89807921531231, 85.35007603434583, 241.95635971015204, -25.102755461228387, 164.3810762311068, 156.9464151368808, 155.10995504761055, 136.57267168112935, 0.0, 53.149165502255364, 200.98208447366665, 197.53479886811024, 82.69263176456117, -7.278212551238809, 222.3457714967922, 81.52957329213805, -7.509951789354052, 163.67551318638576, 85.65287466627308, 45.66623047524298, -32.18639936982642, 152.5041502529267, 143.86515479390638, 72.9287417734735, 193.93608666023908, 194.09053875018455, 95.97188877338867, 96.57346511370555, -32.46336025800864, 6.504501293891862, 32.561920715609624, 20.69246933018626, -3.2506721585682934, 8.896705167660143, -8.360965351205332, -0.0, -32.89712556187716, -19.2797293191564, -26.454728353829495, 15.668156493060867, -67.71704309842804, -2.9530892198040757, -17.338558723663777, -48.52647502388796, 107.93464173090452, -13.333809609205765, 3.2107316878723995, -7.975197258782164, -12.643130882566942, -26.97671027885705, -31.43829028515265, 26.639916226902415, -7.299127514667054, -13.06919288647227, 71.33820528910786, -84.33276554936837, 16.720707690673724, 27.24397737642954, 9.40018721333397, -88.15130880749072, 57.471900380108224, 3.2337929055573897, -21.279855312930145, -0.4019558828880392, -6.793079269139279, 41.28085429307551, -1.7269292587565714, 2.7802745341514483, -18.661764283897156, 17.794790224900506, 3.5299525096156694, -5.634692011283101, -25.010035336395713, -38.13298731250063, 7.835304503367987, 22.105926456313544, 19.381189755554654, -47.81530816324119, 5.211095321545491, 0.0, 8.035445113996595, -49.34583196978446, -0.27419413635586143, -35.39657617255039, -11.288030620082937, -54.86443378083852, -10.596651101070757, 2.047875244904435, 87.844257246688, 130.0336961031593, -60.54761354874705, -17.698409187474333, -34.53949983528737, 0.0, 43.472230651026344, 75.72618376755756, 35.73621992189584, 20.093348957554763, -31.65058387372062, 27.16654833221309, 21.938100114456255, 24.957000720003517, -12.503958242240122, -0.0, -4.7485847109771075, 2.4485206122154985, -11.89374854230436, -1.7617042434551498, 37.126864710659355, 20.477405727252886, 0.0, -0.307761262827194, -5.584602957999561, -26.855484313128777, -26.976712261497354, -31.200729358599787, 7.070193189029051, -18.614949135873932, -6.421239653919545, 3.1567467761799644, -0.0, 63.46844765982592, -22.053554626529284, -10.66142799555631, -78.10193432234227, -9.611593225270221, 84.34537536055214, -0.45877112555776056, 0.0, 1.6926698314370845, -0.0, -0.18126174023014224, 0.0, 9.706753785380116, 36.278461500546406, -5.968759991557666, -2.5870602735354167, 3.089532588224244, -6.024359390116996, 36.02475830024542, -29.034249585838594, 3.003625294981295, -40.20565523126456, -10.001829737079703, 3.3694900623145942, 5.286651846542852, -12.576044931324988, 98.02939781634083, -48.0720104488355, -10.617526584016257, -5.077970725961848, -9.59523798611822, 2.5304051325151096, -5.097454407140856, 33.72963376289568, -26.269314290078142, 17.662106071207386, -36.836090849646105, 7.182185581408473, -16.497714216216277, 3.3694900254395144, -3.0301322395152877, -11.76609044749702, 97.00664052809199, -46.306850584695475, -13.413303502641652, 72.8533516778684, -4.657947244643848, -118.51797943626362, 91.28877243214096, -34.8904797972877, 132.19282944538963, -176.67236209572292, -37.47855125154955, -13.720761353565766, -9.433288881699259, 28.839740376000034, -102.84040675124183, 154.13042445061765, -32.64235405362943, -2.6091514379590164, -0.0, -44.51205432875111, 62.09570487347614, -44.493782932151795, -6.735506124016224, -131.69165010295418, -36.60825856151467, 23.80807110442326, -44.4937834842551, -10.273749848341025, 30.036388610820918, 108.47092087883794, 6.838255208154944, -84.61572239644775, -43.48544924966698, -32.77280672514327, 135.22980860067304, -23.742821220212363, -44.49378388085102, -43.94883163830121, -29.654851329673587, -7.48253225597478, 9.725196343438919, -8.712389455798638, -43.308763162124215, -10.539549657368095, 32.045312766799036, 19.82004021799844, -4.111174240578379, -16.140185327817072, -2.4553707265204796, -14.421353040135779, -36.81935839545978, -36.32483510050797, -11.050759126937297, -99.39178063080855, 77.25787517632916, -34.45353511602918, -15.393597356348717, -5.22932614010588, 69.64620946940286, -41.3342532064658, 85.91130998719821, -2.2492689071253027, -156.0180583174554, -16.705356170836435, -13.130910608125577, -17.31884527536344, -7.285594539823926, -12.554767307971803, -6.01791338105396, 32.06588048964975, -6.030850817862119, 112.19463850104479, -144.60673078963066, -14.77165577086809, 40.49792986757101, 100.20443417830002, -9.921815435178818, 67.0706966745595, -18.45203821981898, -106.5933597364891, -64.61771412458596, -64.50817595934366, 43.20333746476734, -123.46979752965439, -47.57217970875114, 21.142630169977636, -64.50817567340636, -11.775049213689378, 73.40067064894541, -42.218849993423866, 1.1269790287691057, -64.50817521563422, -19.44769684524522, 80.10348025749806, -21.756219215194413, 78.6192017751207, -1.3566607699571704, 4.4378830059620835, -17.701926529608187, -4.143008665145555, -8.166912877167615, 109.28961644619227, -7.789260577493193, -0.28011246852619986, -61.956147455473136, -14.798250988865766, -2.9741770413368154, -8.119540021849149, -43.51561003496967, 108.22007467433805]    180401.21694528876

...

df.dtypes
Out[178]: 
alpha        float64
l1_ratio     float64
mse_path     float64
coef          object
intercept    float64
dtype: object

这会引发错误:

df.pivot(columns = 'alpha', values = ['mse_path','coef'])

..

ValueError: Index contains duplicate entries, cannot reshape

这将返回一个数据透视表,但省略由值列表组成的

coef
变量。

df.pivot_table(columns = 'alpha', values = ['mse_path','coef'])
Out[179]: 
alpha           0.1           1.0     ...        250.0         1000.0
mse_path  5.335019e+08  6.061998e+08  ...  3.950346e+09  4.962799e+09

[1 rows x 9 columns]

我怎样才能实现这个目标?

python pandas pivot pivot-table
1个回答
0
投票

实现的一种方法是首先确保所有条目都适当地聚合到列表中,然后手动构建旋转的 DataFrame。这里我只有您的数据样本,我需要添加一列

alpha
....需要手动处理:

data = {
    'alpha': [1.0, 0.99, 0.95, 0.9, 0.8, 0.75],
    'mse_path': [581499561.8597653, 2214034038.866108, 4477216372.464831, 5295530119.621321, 5841959239.549489, 5965993746.00419],
    'coef': [
        [253.039, 3649.109, -598.486, 28425.471],
        [1288.510, 1141.400, -37.378, 938.122],
        [451.903, 364.427, -119.758, 496.357],
        [251.975, 199.625, -70.678, 369.398],
        [134.197, 105.349, -30.138, 201.609],
        [108.898, 85.350, -25.102, 164.381]
    ],
    'intercept': [180401.21694528882] * 6
}

df = pd.DataFrame(data)

因此,您可以这样做:

pivot_columns = pd.unique(df['alpha'])
index = ['mse_path', 'coef']
pivot_df = pd.DataFrame(columns=pd.MultiIndex.from_product([pivot_columns, index], names=['alpha', 'variable']))

for alpha in pivot_columns:
    for var in index:
        pivot_df.loc[var, (alpha, var)] = list(df[df['alpha'] == alpha][var])

for col in pivot_columns:
    pivot_df.loc['mse_path', (col, 'mse_path')] = pivot_df.loc['mse_path', (col, 'mse_path')][0]

这给出了 或按印刷形式

alpha                 1.00                                              \
variable          mse_path                                        coef   
mse_path  581499561.859765                                         NaN   
coef                   NaN  [[253.039, 3649.109, -598.486, 28425.471]]   

alpha                  0.99                                         \
variable           mse_path                                   coef   
mse_path  2214034038.866108                                    NaN   
coef                    NaN  [[1288.51, 1141.4, -37.378, 938.122]]   

alpha                  0.95                                           \
variable           mse_path                                     coef   
mse_path  4477216372.464831                                      NaN   
coef                    NaN  [[451.903, 364.427, -119.758, 496.357]]   
...
alpha                 0.75                                        
variable          mse_path                                  coef  
mse_path  5965993746.00419                                   NaN  
coef                   NaN  [[108.898, 85.35, -25.102, 164.381]]
© www.soinside.com 2019 - 2024. All rights reserved.