我有很多json文件,格式如下。我想将它们全部加载到一个pandas数据帧中,我计划绘制直方图,绘图,进行算术运算,甚至用scikit学习进行一些聚类。你能否建议一种方法来加载所有这些,以及数据框架的结构,这将使我能够完成我提到的所有内容?它们都有相同的二十个键。
{"ASP": [], "SER": [49.42512893676758, 87.324462890625, 100.39542388916016, 20.75590705871582], "ALA": [59.530941009521484, 81.7466812133789, 88.2237319946289, 30.13962173461914], "TRP": [5.433267593383789], "ASN": [79.04554748535156, 68.15550994873047, 62.12760543823242, 115.7877197265625], "GLU": [112.40697479248047, 151.73361206054688, 137.53512573242188, 32.767948150634766, 137.96853637695312, 53.77445602416992], "MET": [], "TYR": [143.76821899414062], "PRO": [116.5839614868164], "LEU": [0.17834201455116272, 4.947306156158447, 13.47089672088623, 28.727693557739258, 53.70556640625, 37.46043014526367], "GLY": [68.45809936523438], "LYS": [116.17617797851562, 132.67730712890625, 34.025794982910156, 95.01632690429688], "PHE": [14.673666000366211, 2.027207136154175, 33.46115493774414], "HIS": [], "THR": [82.61577606201172, 66.58378601074219], "ARG": [41.769107818603516, 98.1704330444336, 45.386558532714844, 181.3068084716797, 105.4854507446289, 73.10748291015625, 66.13928985595703, 170.6997833251953, 163.4752960205078], "CYS": [], "GLN": [83.19425201416016, 12.17470932006836, 103.35163879394531, 81.73150634765625, 31.622051239013672], "VAL": [], "ILE": [114.99510192871094, 41.7198600769043, 0.0]}
{"ARG": [68.05612182617188, 88.71479797363281, 125.16853332519531, 103.07101440429688, 102.00435638427734, 44.56251907348633, 82.40796661376953, 115.49146270751953, 76.94171905517578, 129.98353576660156, 48.32081985473633, 60.140438079833984, 110.69074249267578, 54.02603530883789, 70.95311737060547, 67.01094818115234, 69.47411346435547, 93.50334930419922, 80.36841583251953, 110.69613647460938], "LEU": [119.96371459960938, 45.58853530883789, 0.9289634823799133, 0.36405861377716064, 76.83800506591797, 0.0, 41.949867248535156, 0.0, 0.41743677854537964, 13.179363250732422, 0.5419187545776367, 0.0, 0.19827242195606232], "ASP": [35.345359802246094, 84.4588394165039, 71.91608428955078, 66.70465850830078, 66.71868896484375, 77.95895385742188, 51.21175003051758, 52.4680061340332, 36.90961837768555, 53.13059616088867, 120.30888366699219, 49.05167007446289, 88.96575927734375], "THR": [107.72725677490234, 48.99312973022461, 14.409412384033203, 66.91473388671875, 86.61380767822266], "ILE": [8.805109024047852, 5.110619068145752, 0.0, 3.855043411254883, 0.35751038789749146, 0.0], "CYS": [0.0, 9.188657760620117, 58.13623809814453, 0.0, 0.9601870775222778, 16.11383628845215, 7.107746124267578], "LYS": [85.11886596679688, 77.05491638183594], "PHE": [25.150365829467773, 3.6460413932800293, 56.869239807128906, 40.0604362487793, 42.66401672363281, 9.597789764404297, 126.21871948242188, 101.59075164794922, 0.0], "VAL": [1.3153986930847168, 0.0, 4.234877586364746, 5.155714511871338, 1.4276752471923828, 6.268824100494385], "SER": [16.802352905273438, 19.02617073059082, 76.10411834716797, 0.0, 76.84957122802734, 0.0, 22.52376937866211, 58.91157531738281, 43.753360748291016, 0.0, 0.0, 69.40901184082031, 6.170444965362549], "ASN": [41.903045654296875, 62.554927825927734, 53.10111999511719, 18.980009078979492, 102.68910217285156, 11.896445274353027], "MET": [79.13356018066406, 170.75839233398438, 0.0, 71.84830474853516, 0.0, 119.38866424560547, 67.38628387451172], "TRP": [7.895239353179932, 5.950051307678223, 0.0, 0.0], "GLN": [98.74332427978516, 79.13684844970703, 115.08076477050781, 19.029775619506836, 119.58193969726562, 92.74263763427734, 11.698519706726074, 137.4556884765625, 138.53060913085938, 106.51445007324219], "PRO": [57.829002380371094, 95.38365173339844, 42.02272033691406, 42.234466552734375, 87.65824890136719, 80.57398223876953, 64.0492935180664, 55.485530853271484], "TYR": [9.822090148925781, 56.0467529296875, 30.431468963623047, 31.76255226135254, 45.439903259277344, 66.53765106201172, 3.171539545059204, 28.238483428955078, 59.58567428588867, 24.219438552856445, 47.06983184814453, 232.45008850097656, 95.66980743408203, 4.800403118133545, 9.222759246826172], "GLU": [82.08787536621094, 107.61881256103516, 22.777896881103516, 80.6388931274414, 82.21851348876953, 25.969308853149414, 72.37361145019531, 109.51012420654297, 36.20577621459961], "ALA": [7.000710487365723, 13.65488052368164], "GLY": [17.85855484008789, 35.2906379699707, 49.52130126953125, 31.411943435668945, 15.257250785827637, 41.99004364013672, 63.7804069519043, 38.36882781982422, 5.514655113220215, 47.7990608215332, 6.874124526977539, 19.127790451049805, 26.578426361083984, 27.13981819152832], "HIS": [110.49043273925781, 162.87278747558594, 36.54679489135742, 58.55682373046875, 59.08997344970703]}
{"ARG": [74.87171936035156, 97.79010772705078, 84.70838928222656, 47.679588317871094, 62.01052474975586, 97.3496322631836, 48.56056213378906, 52.265071868896484, 56.91181945800781, 17.46434211730957], "LEU": [2.4686362743377686, 67.81866455078125, 19.690704345703125, 7.496775150299072, 93.30703735351562, 65.30134582519531, 61.97053527832031, 7.036153793334961, 104.73986053466797, 71.62339782714844, 53.874263763427734, 22.89566993713379, 16.305885314941406, 11.194416999816895, 5.909397125244141, 81.57518005371094, 6.111129283905029, 46.499290466308594, 134.40252685546875, 46.78759765625], "ASP": [99.77772521972656, 24.089035034179688, 74.05118560791016, 94.96992492675781, 83.92030334472656, 76.01729583740234, 35.26525115966797, 27.56204605102539, 77.17794799804688, 95.04708099365234, 63.79326629638672, 39.238059997558594, 125.1258316040039, 152.9127960205078, 58.99921798706055, 44.05112075805664, 79.02959442138672, 2.472879409790039, 63.00210952758789, 156.95899963378906, 11.91939640045166, 44.43429183959961, 113.08647155761719, 45.2503662109375, 11.910050392150879, 0.0, 152.2443389892578], "THR": [52.659305572509766, 22.516292572021484, 11.845416069030762, 4.999425411224365, 82.82980346679688, 0.0, 3.1914939880371094, 3.9230709075927734, 7.8232269287109375, 7.265968322753906, 71.66886901855469, 61.03855895996094, 11.59723949432373, 39.97998809814453, 83.79849243164062, 35.28447723388672, 14.156890869140625, 39.04934310913086, 0.0, 52.02206039428711, 57.09727096557617], "ILE": [85.2587661743164, 90.08553314208984, 102.13269805908203, 0.0, 56.92738342285156, 93.84919738769531, 9.929601669311523, 50.357879638671875, 56.660736083984375, 14.608858108520508, 91.62349700927734, 105.8450927734375], "CYS": [], "LYS": [34.414127349853516, 147.77818298339844, 94.78311920166016, 105.9007339477539, 102.55982971191406, 130.85848999023438, 73.5466537475586, 105.37210845947266, 41.299869537353516, 173.5719757080078, 121.99150848388672, 62.03072738647461, 31.146625518798828, 58.44972229003906, 76.50595092773438, 133.78160095214844, 30.6053466796875, 87.72728729248047], "PHE": [61.21053695678711, 78.57213592529297, 106.42364501953125, 126.73912048339844, 92.43980407714844, 88.37834930419922, 107.69361877441406, 113.16058349609375, 19.519115447998047, 4.089766502380371, 88.70469665527344, 80.2723159790039, 1.3655043840408325, 28.260692596435547, 83.4875717163086, 3.4144790172576904, 93.72084045410156, 122.93299865722656, 144.83419799804688], "VAL": [48.14598083496094, 3.286008596420288, 39.38469696044922, 0.31753045320510864, 6.325417518615723, 36.73872756958008, 70.66659545898438, 16.380882263183594, 9.987236022949219, 3.6488895416259766, 41.29189682006836, 70.87177276611328, 66.25170135498047, 2.722418785095215, 71.26823425292969, 39.88847351074219, 52.71142578125, 5.925907135009766, 61.13005828857422, 9.534090995788574, 0.0, 13.67212963104248, 4.00256872177124], "SER": [13.566607475280762, 43.7506103515625, 23.378332138061523, 51.403446197509766, 18.315418243408203, 9.163564682006836, 100.76903533935547, 118.35162353515625, 23.587982177734375, 21.18052864074707, 3.561875581741333, 3.214515447616577, 1.4345264434814453, 8.978769302368164, 47.63030242919922, 70.26576232910156], "ASN": [50.32886505126953, 83.01547241210938, 125.46541595458984, 52.90938949584961, 39.17740249633789, 77.678955078125, 18.88083839416504, 133.5048828125, 44.297733306884766, 2.2131400108337402, 122.6857681274414, 39.64887619018555, 72.47642517089844, 11.819401741027832, 5.894476413726807, 51.32624435424805, 17.66170883178711, 15.737024307250977, 30.689626693725586, 14.145828247070312, 70.03460693359375, 58.38855743408203, 74.26598358154297, 21.62682342529297, 4.820068836212158, 5.479635238647461, 136.7200164794922, 113.70775604248047, 24.391149520874023, 79.79896545410156], "MET": [60.53358459472656, 74.71451568603516, 60.73385238647461], "TRP": [80.64067077636719, 76.62451171875], "GLN": [128.47154235839844, 0.0, 1.1687817573547363, 4.535152435302734, 50.56570053100586, 124.98794555664062, 38.5822868347168, 78.48471069335938, 50.001861572265625, 55.86512756347656, 75.05795288085938, 34.61421203613281, 9.209488868713379], "PRO": [44.85453414916992, 29.34404945373535, 86.67195129394531, 13.055160522460938, 25.44532012939453], "TYR": [69.23226165771484, 26.69831085205078, 79.70618438720703, 62.49315643310547, 102.47346496582031, 81.84629821777344, 89.19522094726562, 48.0233039855957, 0.7954182624816895, 45.85585021972656, 59.60536193847656, 86.68299865722656, 62.36344528198242, 125.60599517822266, 112.2718276977539, 17.015655517578125, 138.2257843017578, 61.73310470581055, 94.58738708496094, 18.037263870239258, 17.981542587280273, 35.906673431396484, 71.59668731689453, 41.35716247558594, 92.46248626708984, 129.53353881835938, 19.000375747680664, 109.89592742919922, 49.42750549316406], "GLU": [60.75624084472656, 21.04912567138672, 1.843826413154602, 130.5736541748047, 66.43525695800781, 67.84162902832031, 44.04298400878906, 127.90734100341797, 148.5811767578125, 27.686508178710938, 185.4130859375, 110.21463012695312, 84.85928344726562, 64.56336212158203], "ALA": [32.65418243408203, 112.3904037475586, 35.28357696533203, 9.23213005065918, 30.878114700317383, 0.0, 31.779556274414062, 7.4291157722473145, 7.041572093963623, 17.96706199645996, 0.0, 39.72902297973633, 3.8612053394317627, 73.93900299072266, 0.3558747172355652, 62.60910415649414, 17.903358459472656, 6.868346691131592, 25.071338653564453, 41.44161605834961, 59.20819854736328, 54.62333679199219, 4.314484596252441, 0.0, 30.847721099853516, 0.0, 0.0, 35.524192810058594, 3.708381175994873], "GLY": [5.462224960327148, 0.3552100360393524, 84.3140640258789, 29.40142059326172, 34.549747467041016, 21.43756675720215, 5.236337661743164, 30.8936767578125, 4.127312183380127, 12.131168365478516, 7.471875190734863, 5.395791053771973, 18.370540618896484, 1.3406931161880493, 0.5112770199775696, 16.690963745117188, 3.973045825958252, 8.450613975524902, 14.789959907531738, 16.075578689575195, 44.330718994140625, 17.534210205078125, 16.12066650390625, 27.789241790771484, 4.444832801818848, 20.283702850341797, 0.3803024888038635, 10.791778564453125, 25.84272575378418, 9.771528244018555, 19.198429107666016, 12.268213272094727, 25.802833557128906, 36.670860290527344, 68.13138580322266, 13.203579902648926, 42.976932525634766, 4.987290859222412, 24.371000289916992, 28.70888328552246, 0.7481454610824585, 10.800975799560547, 9.660693168640137, 6.688172817230225, 13.039734840393066, 10.348352432250977, 22.49044418334961, 8.2550630569458], "HIS": [70.15235900878906]}
{"ARG": [59.824466705322266, 105.99200439453125, 68.9911117553711, 76.96898651123047], "LEU": [25.90607261657715, 2.4283971786499023, 0.15930123627185822, 60.048561096191406, 17.919889450073242, 0.19595523178577423, 32.9618034362793, 21.82293701171875, 40.58708953857422, 64.52054595947266, 62.78154754638672], "ASP": [68.68733978271484, 36.91146469116211, 80.05387115478516, 56.845088958740234, 27.537824630737305, 31.263343811035156, 129.3114776611328, 91.32628631591797, 68.00175476074219], "THR": [60.49660110473633, 1.2420471906661987, 21.911388397216797, 89.84317016601562, 60.50782775878906, 15.776527404785156, 0.0, 61.48773956298828], "ILE": [57.2337646484375, 7.241193771362305, 15.92918872833252, 5.500481605529785, 1.1929268836975098, 112.57918548583984, 0.0, 0.32226401567459106, 55.615196228027344, 0.0, 0.0, 4.746074199676514, 47.26011657714844, 3.267803907394409, 0.0], "CYS": [], "LYS": [78.66463470458984, 69.79967498779297, 136.32730102539062, 85.02759552001953, 99.6641616821289, 93.99827575683594, 162.09742736816406, 80.24180603027344], "PHE": [56.745391845703125, 0.0, 18.023460388183594, 15.538548469543457, 88.83783721923828, 28.55647850036621, 3.9971766471862793, 0.9002707004547119], "VAL": [29.844329833984375, 1.4805861711502075, 11.789131164550781, 14.659979820251465, 18.24456787109375, 1.2091726064682007, 8.316301345825195, 8.708450317382812, 2.6055750846862793, 0.0, 4.395174026489258, 92.84371948242188, 17.020751953125, 0.7387140393257141, 0.18118613958358765, 18.726093292236328, 18.74958610534668, 63.58165740966797], "SER": [0.0, 36.893531799316406, 84.7409896850586, 21.409486770629883, 75.42151641845703, 26.905813217163086, 39.22748947143555, 4.184535026550293, 100.0130386352539, 91.46409606933594, 0.0, 64.78292083740234], "ASN": [87.05628204345703, 96.39205932617188, 63.46795654296875, 60.95703887939453, 35.03052520751953], "MET": [15.452376365661621, 130.6868438720703, 85.16622924804688], "TRP": [], "GLN": [54.356475830078125, 61.75361633300781, 66.4168701171875, 132.8467559814453, 117.10356903076172], "PRO": [75.34269714355469, 85.17718505859375, 120.70584106445312, 0.5000942945480347, 0.0, 44.31075668334961, 60.28285598754883, 97.11192321777344, 99.93550872802734, 0.0, 14.000977516174316], "TYR": [], "GLU": [107.00129699707031, 53.36533737182617, 110.62167358398438, 96.30351257324219, 163.9122314453125, 133.6676483154297, 56.61357498168945, 111.49232482910156, 164.9582061767578, 59.992286682128906, 72.02396392822266, 111.19728088378906, 189.7711639404297, 80.73261260986328, 77.5806884765625, 67.1955337524414], "ALA": [53.418190002441406, 41.32647705078125, 18.19795799255371, 0.0, 0.0], "GLY": [40.038848876953125, 50.17283630371094, 15.844901084899902, 68.60974884033203, 10.757667541503906, 39.587432861328125, 5.147840976715088, 24.778383255004883, 20.51225471496582, 0.0, 20.5284423828125, 0.0, 41.33810806274414, 2.5785295963287354, 9.024069786071777, 29.5589599609375, 34.66822814941406], "HIS": [24.960866928100586, 4.543171405792236, 32.918678283691406]}
{"ARG": [156.55580139160156, 243.37489318847656, 246.0595703125, 241.3383331298828, 139.3704833984375, 61.648582458496094, 53.3700065612793, 53.93013381958008, 104.28936767578125, 3.444389581680298, 177.75222778320312, 159.60333251953125], "LEU": [121.28601837158203, 0.0, 57.0919303894043, 0.5586429834365845, 100.89956665039062, 8.463929176330566, 51.950965881347656, 8.347567558288574, 0.0, 3.037151575088501, 29.123531341552734, 2.396103620529175, 20.346343994140625, 48.62136459350586, 52.27664566040039, 15.416816711425781], "ASP": [201.95724487304688, 130.11061096191406, 0.0, 220.57196044921875, 41.52070236206055, 270.2710876464844, 146.41407775878906, 256.1359558105469, 205.02908325195312, 182.0364227294922, 47.5296630859375], "THR": [17.166120529174805, 6.624889850616455, 6.421140670776367, 8.544548034667969, 149.9822235107422, 140.2353057861328, 15.870949745178223, 178.67689514160156, 102.61243438720703], "ILE": [1.1171156167984009, 5.367067337036133, 0.0, 12.165700912475586, 6.673050880432129, 0.0, 10.308551788330078, 0.541118323802948, 123.2101058959961, 0.17834201455116272, 2.0002007484436035], "CYS": [], "LYS": [268.91387939453125, 280.9231262207031, 262.757568359375, 216.9283447265625, 234.3345489501953, 197.8124237060547, 122.67249298095703], "PHE": [58.89387893676758, 1.9944243431091309, 6.092949390411377, 113.68316650390625, 63.418609619140625, 0.0, 45.024173736572266], "VAL": [2.529179334640503, 0.179544135928154, 0.37036699056625366, 69.11801147460938, 1.014648199081421, 5.054221153259277, 2.593496561050415, 4.803696632385254, 12.664349555969238, 66.39627838134766, 3.5026159286499023], "SER": [23.45200538635254, 138.01861572265625, 49.9803352355957, 51.60409927368164, 25.827030181884766, 77.16778564453125, 11.8124361038208, 100.08522033691406, 75.2754135131836, 31.883031845092773, 158.32028198242188], "ASN": [0.4790339171886444, 140.1581268310547, 48.912994384765625, 79.49222564697266, 164.35299682617188, 59.53786849975586, 99.34628295898438, 7.584788799285889, 155.8171844482422, 38.23351287841797, 58.47761917114258, 61.76235580444336, 0.7042398452758789, 34.44757080078125, 289.3428649902344, 213.1811065673828, 169.76742553710938, 177.02313232421875, 257.7198181152344, 141.43121337890625, 26.071325302124023, 110.10904693603516], "MET": [0.0, 135.21502685546875, 4.572327136993408, 5.620458126068115], "TRP": [2.5049262046813965, 21.66659164428711, 0.9177783131599426, 21.965187072753906, 9.921331405639648, 25.36182975769043, 0.9714438915252686], "GLN": [151.2491455078125, 220.71107482910156, 244.73695373535156, 192.57981872558594, 243.5409698486328, 201.11697387695312, 237.5204315185547, 151.67250061035156, 0.6372577548027039, 301.2269592285156, 101.21388244628906, 76.67669677734375, 309.03765869140625, 75.49212646484375], "PRO": [70.43501281738281, 98.12938690185547, 4.025827407836914, 0.17591436207294464, 38.64352798461914, 40.64609146118164, 122.27778625488281, 153.61798095703125, 153.61447143554688, 214.31094360351562, 177.81541442871094, 198.04824829101562, 177.73193359375], "TYR": [5.023026943206787, 19.32341194152832, 33.284358978271484, 3.8656976222991943, 63.007110595703125, 52.66779708862305, 19.09878158569336, 142.0982666015625], "GLU": [88.12334442138672, 207.62538146972656, 169.29652404785156, 157.3662109375, 1.2636126279830933, 29.700687408447266, 238.5840301513672, 260.5592956542969, 243.4847412109375, 193.77867126464844, 149.60926818847656, 50.672332763671875, 311.0204772949219], "ALA": [106.68447875976562, 12.842738151550293, 35.95348358154297, 33.75405502319336, 9.907773971557617, 43.704742431640625, 0.58897864818573, 33.851497650146484, 78.78157806396484, 93.78713989257812, 9.544583320617676, 65.60578155517578], "GLY": [1.860490083694458, 0.0, 74.20130157470703, 101.0248031616211, 0.0, 93.51673126220703, 1.3560885190963745, 9.048789978027344, 79.65489196777344, 1.0826789140701294, 104.08602142333984, 0.0, 2.0093765258789062, 37.903968811035156, 91.64290618896484, 38.422950744628906, 114.90951538085938, 72.11737823486328], "HIS": [65.15504455566406, 0.0, 10.588594436645508, 38.082279205322266, 0.0, 1.0976781845092773, 3.2833797931671143, 17.43886947631836]}
如果您认为这些词典会给我带来问题或者是表示我的数据的次优方式,您能否建议另一种格式来保存我的数据,以便以后更容易操作?
编辑: 我只想把它转换成熊猫,因为有人建议这样做。如果你解释你所选择的结构如何进行操作,比如平均某个键的所有值,比如'ARG',在所有json中,或者绘制一个特定键的所有值的直方图,那么我将不胜感激!
编辑2:
两件事:
一:我是Pandas的新手,所以如果你评论下面写的代码来帮助我理解你做了什么,我将不胜感激。顺便说一句,我打印出数据帧,它看起来并不具有吸引力。
二:我最终选择了一种字典格式来输出我的数据以保存所有信息,现在就像这样:
{"1enh_n.pdb": {"ILE": [0.0, 41.7198600769043, 114.99510192871094], "HIS": [], "SER": [100.39542388916016, 87.324462890625, 20.75590705871582, 49.42512893676758], "ASP": [], "TRP": [5.433267593383789], "LEU": [4.947306156158447, 37.46043014526367, 28.727693557739258, 53.70556640625, 0.17834201455116272, 13.47089672088623], "PHE": [2.027207136154175, 14.673666000366211, 33.46115493774414], "ALA": [88.2237319946289, 30.13962173461914, 59.530941009521484, 81.7466812133789], "VAL": [], "THR": [82.61577606201172, 66.58378601074219], "ASN": [62.12760543823242, 79.04554748535156, 68.15550994873047, 115.7877197265625], "GLY": [68.45809936523438], "GLU": [137.96853637695312, 151.73361206054688, 137.53512573242188, 32.767948150634766, 53.77445602416992, 112.40697479248047], "GLN": [103.35163879394531, 83.19425201416016, 81.73150634765625, 31.622051239013672, 12.17470932006836], "PRO": [116.5839614868164], "LYS": [132.67730712890625, 95.01632690429688, 34.025794982910156, 116.17617797851562], "TYR": [143.76821899414062], "ARG": [163.4752960205078, 66.13928985595703, 73.10748291015625, 105.4854507446289, 170.6997833251953, 45.386558532714844, 181.3068084716797, 41.769107818603516, 98.1704330444336], "CYS": [], "MET": []}}
文件名是键,值是所有残基的字典作为键和每个的一些数字的列表。然后我可以加载所有这些json文件并使用update()将它们全部加入一个大字典中。如何改变你在那里写下的代码?
答案 0 :(得分:0)
假设data
是您示例中的词典列表,我会这样做:
pd.DataFrame([pd.DataFrame(dict([(x,pd.Series(y))
for x,y in line.items()])).unstack().dropna()
for line in data]).T
框架如下所示:
# 0 1
#ALA 0 7.000710 59.530941
# 1 13.654881 81.746681
# 2 NaN 88.223732
# 3 NaN 30.139622
#ARG 0 68.056122 41.769108
# 1 88.714798 98.170433
# 2 125.168533 45.386559
#... . .......... .........
列名是原始JSON中的行索引。
答案 1 :(得分:0)
让我们打破这个json, 假设你有一个json文件temp2.json
{"ASP": [], "SER": [49.42512893676758, 87.324462890625, 100.39542388916016, 20.75590705871582], "ALA": [59.530941009521484, 81.7466812133789, 88.2237319946289, 30.13962173461914], "TRP": [5.433267593383789], "ASN": [79.04554748535156, 68.15550994873047, 62.12760543823242, 115.7877197265625], "GLU": [112.40697479248047, 151.73361206054688, 137.53512573242188, 32.767948150634766, 137.96853637695312, 53.77445602416992], "MET": [], "TYR": [143.76821899414062], "PRO": [116.5839614868164], "LEU": [0.17834201455116272, 4.947306156158447, 13.47089672088623, 28.727693557739258, 53.70556640625, 37.46043014526367], "GLY": [68.45809936523438], "LYS": [116.17617797851562, 132.67730712890625, 34.025794982910156, 95.01632690429688], "PHE": [14.673666000366211, 2.027207136154175, 33.46115493774414], "HIS": [], "THR": [82.61577606201172, 66.58378601074219], "ARG": [41.769107818603516, 98.1704330444336, 45.386558532714844, 181.3068084716797, 105.4854507446289, 73.10748291015625, 66.13928985595703, 170.6997833251953, 163.4752960205078], "CYS": [], "GLN": [83.19425201416016, 12.17470932006836, 103.35163879394531, 81.73150634765625, 31.622051239013672], "VAL": [], "ILE": [114.99510192871094, 41.7198600769043, 0.0]}
现在您可以使用以下方法将其加载到数据框中:
import json
import pandas as pd
# Reading the json as a dict
with open('temp2.json') as json_data:
data = json.load(json_data)
df = pd.DataFrame.from_dict(data, orient='index').T
希望这有帮助
答案 2 :(得分:0)
假设您有一个json文件 temp.json
{"ASP": [], "SER": [49.42512893676758, 87.324462890625, 100.39542388916016, 20.75590705871582], "ALA": [59.530941009521484, 81.7466812133789, 88.2237319946289, 30.13962173461914], "TRP": [5.433267593383789], "ASN": [79.04554748535156, 68.15550994873047, 62.12760543823242, 115.7877197265625], "GLU": [112.40697479248047, 151.73361206054688, 137.53512573242188, 32.767948150634766, 137.96853637695312, 53.77445602416992], "MET": [], "TYR": [143.76821899414062], "PRO": [116.5839614868164], "LEU": [0.17834201455116272, 4.947306156158447, 13.47089672088623, 28.727693557739258, 53.70556640625, 37.46043014526367], "GLY": [68.45809936523438], "LYS": [116.17617797851562, 132.67730712890625, 34.025794982910156, 95.01632690429688], "PHE": [14.673666000366211, 2.027207136154175, 33.46115493774414], "HIS": [], "THR": [82.61577606201172, 66.58378601074219], "ARG": [41.769107818603516, 98.1704330444336, 45.386558532714844, 181.3068084716797, 105.4854507446289, 73.10748291015625, 66.13928985595703, 170.6997833251953, 163.4752960205078], "CYS": [], "GLN": [83.19425201416016, 12.17470932006836, 103.35163879394531, 81.73150634765625, 31.622051239013672], "VAL": [], "ILE": [114.99510192871094, 41.7198600769043, 0.0]}
{"ARG": [68.05612182617188, 88.71479797363281, 125.16853332519531, 103.07101440429688, 102.00435638427734, 44.56251907348633, 82.40796661376953, 115.49146270751953, 76.94171905517578, 129.98353576660156, 48.32081985473633, 60.140438079833984, 110.69074249267578, 54.02603530883789, 70.95311737060547, 67.01094818115234, 69.47411346435547, 93.50334930419922, 80.36841583251953, 110.69613647460938], "LEU": [119.96371459960938, 45.58853530883789, 0.9289634823799133, 0.36405861377716064, 76.83800506591797, 0.0, 41.949867248535156, 0.0, 0.41743677854537964, 13.179363250732422, 0.5419187545776367, 0.0, 0.19827242195606232], "ASP": [35.345359802246094, 84.4588394165039, 71.91608428955078, 66.70465850830078, 66.71868896484375, 77.95895385742188, 51.21175003051758, 52.4680061340332, 36.90961837768555, 53.13059616088867, 120.30888366699219, 49.05167007446289, 88.96575927734375], "THR": [107.72725677490234, 48.99312973022461, 14.409412384033203, 66.91473388671875, 86.61380767822266], "ILE": [8.805109024047852, 5.110619068145752, 0.0, 3.855043411254883, 0.35751038789749146, 0.0], "CYS": [0.0, 9.188657760620117, 58.13623809814453, 0.0, 0.9601870775222778, 16.11383628845215, 7.107746124267578], "LYS": [85.11886596679688, 77.05491638183594], "PHE": [25.150365829467773, 3.6460413932800293, 56.869239807128906, 40.0604362487793, 42.66401672363281, 9.597789764404297, 126.21871948242188, 101.59075164794922, 0.0], "VAL": [1.3153986930847168, 0.0, 4.234877586364746, 5.155714511871338, 1.4276752471923828, 6.268824100494385], "SER": [16.802352905273438, 19.02617073059082, 76.10411834716797, 0.0, 76.84957122802734, 0.0, 22.52376937866211, 58.91157531738281, 43.753360748291016, 0.0, 0.0, 69.40901184082031, 6.170444965362549], "ASN": [41.903045654296875, 62.554927825927734, 53.10111999511719, 18.980009078979492, 102.68910217285156, 11.896445274353027], "MET": [79.13356018066406, 170.75839233398438, 0.0, 71.84830474853516, 0.0, 119.38866424560547, 67.38628387451172], "TRP": [7.895239353179932, 5.950051307678223, 0.0, 0.0], "GLN": [98.74332427978516, 79.13684844970703, 115.08076477050781, 19.029775619506836, 119.58193969726562, 92.74263763427734, 11.698519706726074, 137.4556884765625, 138.53060913085938, 106.51445007324219], "PRO": [57.829002380371094, 95.38365173339844, 42.02272033691406, 42.234466552734375, 87.65824890136719, 80.57398223876953, 64.0492935180664, 55.485530853271484], "TYR": [9.822090148925781, 56.0467529296875, 30.431468963623047, 31.76255226135254, 45.439903259277344, 66.53765106201172, 3.171539545059204, 28.238483428955078, 59.58567428588867, 24.219438552856445, 47.06983184814453, 232.45008850097656, 95.66980743408203, 4.800403118133545, 9.222759246826172], "GLU": [82.08787536621094, 107.61881256103516, 22.777896881103516, 80.6388931274414, 82.21851348876953, 25.969308853149414, 72.37361145019531, 109.51012420654297, 36.20577621459961], "ALA": [7.000710487365723, 13.65488052368164], "GLY": [17.85855484008789, 35.2906379699707, 49.52130126953125, 31.411943435668945, 15.257250785827637, 41.99004364013672, 63.7804069519043, 38.36882781982422, 5.514655113220215, 47.7990608215332, 6.874124526977539, 19.127790451049805, 26.578426361083984, 27.13981819152832], "HIS": [110.49043273925781, 162.87278747558594, 36.54679489135742, 58.55682373046875, 59.08997344970703]}
{"ARG": [74.87171936035156, 97.79010772705078, 84.70838928222656, 47.679588317871094, 62.01052474975586, 97.3496322631836, 48.56056213378906, 52.265071868896484, 56.91181945800781, 17.46434211730957], "LEU": [2.4686362743377686, 67.81866455078125, 19.690704345703125, 7.496775150299072, 93.30703735351562, 65.30134582519531, 61.97053527832031, 7.036153793334961, 104.73986053466797, 71.62339782714844, 53.874263763427734, 22.89566993713379, 16.305885314941406, 11.194416999816895, 5.909397125244141, 81.57518005371094, 6.111129283905029, 46.499290466308594, 134.40252685546875, 46.78759765625], "ASP": [99.77772521972656, 24.089035034179688, 74.05118560791016, 94.96992492675781, 83.92030334472656, 76.01729583740234, 35.26525115966797, 27.56204605102539, 77.17794799804688, 95.04708099365234, 63.79326629638672, 39.238059997558594, 125.1258316040039, 152.9127960205078, 58.99921798706055, 44.05112075805664, 79.02959442138672, 2.472879409790039, 63.00210952758789, 156.95899963378906, 11.91939640045166, 44.43429183959961, 113.08647155761719, 45.2503662109375, 11.910050392150879, 0.0, 152.2443389892578], "THR": [52.659305572509766, 22.516292572021484, 11.845416069030762, 4.999425411224365, 82.82980346679688, 0.0, 3.1914939880371094, 3.9230709075927734, 7.8232269287109375, 7.265968322753906, 71.66886901855469, 61.03855895996094, 11.59723949432373, 39.97998809814453, 83.79849243164062, 35.28447723388672, 14.156890869140625, 39.04934310913086, 0.0, 52.02206039428711, 57.09727096557617], "ILE": [85.2587661743164, 90.08553314208984, 102.13269805908203, 0.0, 56.92738342285156, 93.84919738769531, 9.929601669311523, 50.357879638671875, 56.660736083984375, 14.608858108520508, 91.62349700927734, 105.8450927734375], "CYS": [], "LYS": [34.414127349853516, 147.77818298339844, 94.78311920166016, 105.9007339477539, 102.55982971191406, 130.85848999023438, 73.5466537475586, 105.37210845947266, 41.299869537353516, 173.5719757080078, 121.99150848388672, 62.03072738647461, 31.146625518798828, 58.44972229003906, 76.50595092773438, 133.78160095214844, 30.6053466796875, 87.72728729248047], "PHE": [61.21053695678711, 78.57213592529297, 106.42364501953125, 126.73912048339844, 92.43980407714844, 88.37834930419922, 107.69361877441406, 113.16058349609375, 19.519115447998047, 4.089766502380371, 88.70469665527344, 80.2723159790039, 1.3655043840408325, 28.260692596435547, 83.4875717163086, 3.4144790172576904, 93.72084045410156, 122.93299865722656, 144.83419799804688], "VAL": [48.14598083496094, 3.286008596420288, 39.38469696044922, 0.31753045320510864, 6.325417518615723, 36.73872756958008, 70.66659545898438, 16.380882263183594, 9.987236022949219, 3.6488895416259766, 41.29189682006836, 70.87177276611328, 66.25170135498047, 2.722418785095215, 71.26823425292969, 39.88847351074219, 52.71142578125, 5.925907135009766, 61.13005828857422, 9.534090995788574, 0.0, 13.67212963104248, 4.00256872177124], "SER": [13.566607475280762, 43.7506103515625, 23.378332138061523, 51.403446197509766, 18.315418243408203, 9.163564682006836, 100.76903533935547, 118.35162353515625, 23.587982177734375, 21.18052864074707, 3.561875581741333, 3.214515447616577, 1.4345264434814453, 8.978769302368164, 47.63030242919922, 70.26576232910156], "ASN": [50.32886505126953, 83.01547241210938, 125.46541595458984, 52.90938949584961, 39.17740249633789, 77.678955078125, 18.88083839416504, 133.5048828125, 44.297733306884766, 2.2131400108337402, 122.6857681274414, 39.64887619018555, 72.47642517089844, 11.819401741027832, 5.894476413726807, 51.32624435424805, 17.66170883178711, 15.737024307250977, 30.689626693725586, 14.145828247070312, 70.03460693359375, 58.38855743408203, 74.26598358154297, 21.62682342529297, 4.820068836212158, 5.479635238647461, 136.7200164794922, 113.70775604248047, 24.391149520874023, 79.79896545410156], "MET": [60.53358459472656, 74.71451568603516, 60.73385238647461], "TRP": [80.64067077636719, 76.62451171875], "GLN": [128.47154235839844, 0.0, 1.1687817573547363, 4.535152435302734, 50.56570053100586, 124.98794555664062, 38.5822868347168, 78.48471069335938, 50.001861572265625, 55.86512756347656, 75.05795288085938, 34.61421203613281, 9.209488868713379], "PRO": [44.85453414916992, 29.34404945373535, 86.67195129394531, 13.055160522460938, 25.44532012939453], "TYR": [69.23226165771484, 26.69831085205078, 79.70618438720703, 62.49315643310547, 102.47346496582031, 81.84629821777344, 89.19522094726562, 48.0233039855957, 0.7954182624816895, 45.85585021972656, 59.60536193847656, 86.68299865722656, 62.36344528198242, 125.60599517822266, 112.2718276977539, 17.015655517578125, 138.2257843017578, 61.73310470581055, 94.58738708496094, 18.037263870239258, 17.981542587280273, 35.906673431396484, 71.59668731689453, 41.35716247558594, 92.46248626708984, 129.53353881835938, 19.000375747680664, 109.89592742919922, 49.42750549316406], "GLU": [60.75624084472656, 21.04912567138672, 1.843826413154602, 130.5736541748047, 66.43525695800781, 67.84162902832031, 44.04298400878906, 127.90734100341797, 148.5811767578125, 27.686508178710938, 185.4130859375, 110.21463012695312, 84.85928344726562, 64.56336212158203], "ALA": [32.65418243408203, 112.3904037475586, 35.28357696533203, 9.23213005065918, 30.878114700317383, 0.0, 31.779556274414062, 7.4291157722473145, 7.041572093963623, 17.96706199645996, 0.0, 39.72902297973633, 3.8612053394317627, 73.93900299072266, 0.3558747172355652, 62.60910415649414, 17.903358459472656, 6.868346691131592, 25.071338653564453, 41.44161605834961, 59.20819854736328, 54.62333679199219, 4.314484596252441, 0.0, 30.847721099853516, 0.0, 0.0, 35.524192810058594, 3.708381175994873], "GLY": [5.462224960327148, 0.3552100360393524, 84.3140640258789, 29.40142059326172, 34.549747467041016, 21.43756675720215, 5.236337661743164, 30.8936767578125, 4.127312183380127, 12.131168365478516, 7.471875190734863, 5.395791053771973, 18.370540618896484, 1.3406931161880493, 0.5112770199775696, 16.690963745117188, 3.973045825958252, 8.450613975524902, 14.789959907531738, 16.075578689575195, 44.330718994140625, 17.534210205078125, 16.12066650390625, 27.789241790771484, 4.444832801818848, 20.283702850341797, 0.3803024888038635, 10.791778564453125, 25.84272575378418, 9.771528244018555, 19.198429107666016, 12.268213272094727, 25.802833557128906, 36.670860290527344, 68.13138580322266, 13.203579902648926, 42.976932525634766, 4.987290859222412, 24.371000289916992, 28.70888328552246, 0.7481454610824585, 10.800975799560547, 9.660693168640137, 6.688172817230225, 13.039734840393066, 10.348352432250977, 22.49044418334961, 8.2550630569458], "HIS": [70.15235900878906]}
{"ARG": [59.824466705322266, 105.99200439453125, 68.9911117553711, 76.96898651123047], "LEU": [25.90607261657715, 2.4283971786499023, 0.15930123627185822, 60.048561096191406, 17.919889450073242, 0.19595523178577423, 32.9618034362793, 21.82293701171875, 40.58708953857422, 64.52054595947266, 62.78154754638672], "ASP": [68.68733978271484, 36.91146469116211, 80.05387115478516, 56.845088958740234, 27.537824630737305, 31.263343811035156, 129.3114776611328, 91.32628631591797, 68.00175476074219], "THR": [60.49660110473633, 1.2420471906661987, 21.911388397216797, 89.84317016601562, 60.50782775878906, 15.776527404785156, 0.0, 61.48773956298828], "ILE": [57.2337646484375, 7.241193771362305, 15.92918872833252, 5.500481605529785, 1.1929268836975098, 112.57918548583984, 0.0, 0.32226401567459106, 55.615196228027344, 0.0, 0.0, 4.746074199676514, 47.26011657714844, 3.267803907394409, 0.0], "CYS": [], "LYS": [78.66463470458984, 69.79967498779297, 136.32730102539062, 85.02759552001953, 99.6641616821289, 93.99827575683594, 162.09742736816406, 80.24180603027344], "PHE": [56.745391845703125, 0.0, 18.023460388183594, 15.538548469543457, 88.83783721923828, 28.55647850036621, 3.9971766471862793, 0.9002707004547119], "VAL": [29.844329833984375, 1.4805861711502075, 11.789131164550781, 14.659979820251465, 18.24456787109375, 1.2091726064682007, 8.316301345825195, 8.708450317382812, 2.6055750846862793, 0.0, 4.395174026489258, 92.84371948242188, 17.020751953125, 0.7387140393257141, 0.18118613958358765, 18.726093292236328, 18.74958610534668, 63.58165740966797], "SER": [0.0, 36.893531799316406, 84.7409896850586, 21.409486770629883, 75.42151641845703, 26.905813217163086, 39.22748947143555, 4.184535026550293, 100.0130386352539, 91.46409606933594, 0.0, 64.78292083740234], "ASN": [87.05628204345703, 96.39205932617188, 63.46795654296875, 60.95703887939453, 35.03052520751953], "MET": [15.452376365661621, 130.6868438720703, 85.16622924804688], "TRP": [], "GLN": [54.356475830078125, 61.75361633300781, 66.4168701171875, 132.8467559814453, 117.10356903076172], "PRO": [75.34269714355469, 85.17718505859375, 120.70584106445312, 0.5000942945480347, 0.0, 44.31075668334961, 60.28285598754883, 97.11192321777344, 99.93550872802734, 0.0, 14.000977516174316], "TYR": [], "GLU": [107.00129699707031, 53.36533737182617, 110.62167358398438, 96.30351257324219, 163.9122314453125, 133.6676483154297, 56.61357498168945, 111.49232482910156, 164.9582061767578, 59.992286682128906, 72.02396392822266, 111.19728088378906, 189.7711639404297, 80.73261260986328, 77.5806884765625, 67.1955337524414], "ALA": [53.418190002441406, 41.32647705078125, 18.19795799255371, 0.0, 0.0], "GLY": [40.038848876953125, 50.17283630371094, 15.844901084899902, 68.60974884033203, 10.757667541503906, 39.587432861328125, 5.147840976715088, 24.778383255004883, 20.51225471496582, 0.0, 20.5284423828125, 0.0, 41.33810806274414, 2.5785295963287354, 9.024069786071777, 29.5589599609375, 34.66822814941406], "HIS": [24.960866928100586, 4.543171405792236, 32.918678283691406]}
让我们编写一个代码来填充数据框
import pandas as pd
import simplejson as json
#this will merge all the json into one DataFrame
df = pd.DataFrame({})
lines = tuple(open('temp.json', 'r'))
lines = ' '.join(map(str,lines))
line = lines.split('\n')
for l in line:
data = json.loads(l)
curr_df = pd.DataFrame.from_dict(data, orient='index').T
df = pd.concat([df,curr_df])
df = df.reset_index()
#Print average
df['ARG'].mean()
#plot histogram
df['ARG'].hist()