我有一系列大数据帧。该数字将根据代码的输入而变化。然后,每个数据帧将再次具有不同数量的行和列。字典中每个数据框的列数均相同,但各数据框之间的行数会有所不同。这是我字典中的一个数据框:
{'093nb-a': 1 2 3 4 5 6 7 8 9 10 ... 31 32 33 34 35 36 37 38 39 40
product ...
043-096(L00) 0.0 0.0 0.0 0.0 0.0 0.000000e+00 0.000000e+00 1.928800e-02 2.221950e-01 2.104710 ... 10.684400 8.809840 7.921030 6.975370 6.472240e+00 5.643140e+00 5.340900e+00 5.088400e+00 4.468070e+00 4.092830e+00
041-092(L01) 0.0 0.0 0.0 0.0 0.0 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000000 ... 27.343100 26.348200 27.005100 25.692700 2.433850e+01 2.312400e+01 2.292020e+01 2.166400e+01 2.062450e+01 1.961710e+01
043-093(L01) 0.0 0.0 0.0 0.0 0.0 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000000 ... 0.000000 0.000000 0.000000 0.000000 0.000000e+00 2.019000e-01 1.145850e+00 6.568850e+00 1.580680e+01 2.964780e+01
041-093(L00) 0.0 0.0 0.0 0.0 0.0 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.001590 ... 54.059900 49.499700 45.770400 43.115200 4.162900e+01 3.929880e+01 3.760480e+01 3.625430e+01 3.542060e+01 3.510910e+01
041-093(L01) 0.0 0.0 0.0 0.0 0.0 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000272 ... 9.123110 8.516590 7.405670 6.951680 6.639450e+00 6.371910e+00 5.821850e+00 5.535770e+00 5.392260e+00 5.291000e+00
043-096(L01) 0.0 0.0 0.0 0.0 0.0 0.000000e+00 0.000000e+00 8.488600e-03 1.094350e-01 0.975641 ... 2.517700 2.374990 2.345830 2.002980 1.865650e+00 1.750060e+00 1.715700e+00 1.681990e+00 1.358840e+00 1.296470e+00
042-093(L16) 0.0 0.0 0.0 0.0 0.0 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000000 ... 0.012354 0.035613 0.065930 0.100664 1.729990e-01 1.172700e+00 1.178630e+01 3.434970e+01 7.109020e+01 1.136440e+02
043-093(L00) 0.0 0.0 0.0 0.0 0.0 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000000 ... 0.000000 0.000000 0.000000 0.000000 7.288420e-01 8.628490e+00 3.177190e+01 7.529960e+01 1.314360e+02 1.981620e+02
041-095(L01) 0.0 0.0 0.0 0.0 0.0 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000000 ... 0.004043 0.005084 0.006025 0.007093 7.659520e-03 8.165380e-03 8.903470e-03 8.237130e-03 8.687170e-03 9.185370e-03
042-093(L00) 0.0 0.0 0.0 0.0 0.0 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000000 ... 0.308164 0.535273 0.776155 1.971320 6.158180e+00 1.346020e+01 2.028300e+01 2.922050e+01 3.994700e+01 5.241390e+01
043-095(L00) 0.0 0.0 0.0 0.0 0.0 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000000 ... 512.543000 412.627000 317.795000 233.591000 1.838820e+02 1.453260e+02 1.051780e+02 7.979190e+01 6.791930e+01 5.806560e+01
043-094(L01) 0.0 0.0 0.0 0.0 0.0 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000000 ... 21.799500 24.550900 26.159300 25.745400 2.536940e+01 2.359510e+01 2.092200e+01 1.799270e+01 1.547530e+01 1.292230e+01
041-092(L00) 0.0 0.0 0.0 0.0 0.0 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000000 ... 64.925000 66.531400 66.476800 64.894800 6.148120e+01 5.922860e+01 5.580080e+01 5.150720e+01 4.853910e+01 4.493510e+01
041-095(L00) 0.0 0.0 0.0 0.0 0.0 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000000 ... 0.069713 0.092968 0.114729 0.138480 1.453310e-01 1.530490e-01 1.583970e-01 1.407330e-01 1.371880e-01 1.355580e-01
041-091(L00) 0.0 0.0 0.0 0.0 0.0 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000000 ... 30.032300 40.332400 44.996500 47.000700 5.271180e+01 5.372560e+01 5.788070e+01 6.146730e+01 6.655750e+01 7.144250e+01
041-090(L02) 0.0 0.0 0.0 0.0 0.0 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000000 ... 0.000000 0.000000 0.000000 0.000000 0.000000e+00 0.000000e+00 5.594050e-05 8.369660e-04 2.903470e-03 1.917730e-02
041-090(L00) 0.0 0.0 0.0 0.0 0.0 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000000 ... 0.000000 0.000000 0.000000 0.000000 0.000000e+00 0.000000e+00 1.534300e-03 8.703700e-03 4.770440e-02 1.738080e-01
041-094(L01) 0.0 0.0 0.0 0.0 0.0 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000000 ... 0.532802 0.720289 0.929777 1.033430 1.254450e+00 1.385020e+00 1.635600e+00 1.817290e+00 2.056140e+00 2.293480e+00
043-094(L00) 0.0 0.0 0.0 0.0 0.0 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000000 ... 519.805000 620.513000 724.166000 820.729000 8.732280e+02 9.074630e+02 9.164940e+02 8.776860e+02 7.838060e+02 6.768200e+02
041-091(L01) 0.0 0.0 0.0 0.0 0.0 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000000 ... 6.299650 10.849700 12.339300 14.101300 1.685690e+01 1.810710e+01 2.097550e+01 2.283200e+01 2.553310e+01 2.845680e+01
039-089(L01) 0.0 0.0 0.0 0.0 0.0 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000000 ... 0.021291 0.028549 0.037696 0.051105 6.335970e-02 7.822260e-02 9.664860e-02 1.074630e-01 1.214690e-01 1.348120e-01
043-097(L01) 0.0 0.0 0.0 0.0 0.0 2.299380e-12 2.137050e-07 1.618280e-08 4.806170e-08 0.000215 ... 0.000004 0.000003 0.000003 0.000002 4.996970e-07 1.754870e-07 7.402690e-08 5.900700e-08 1.725820e-08 1.416280e-08
041-094(L00) 0.0 0.0 0.0 0.0 0.0 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000000 ... 0.224109 0.329906 0.465128 0.574359 7.598240e-01 9.471510e-01 1.195480e+00 1.458680e+00 1.727560e+00 2.054990e+00
039-089(L00) 0.0 0.0 0.0 0.0 0.0 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000000 ... 0.010328 0.013777 0.013199 0.015000 1.716070e-02 1.983690e-02 2.039220e-02 2.140960e-02 2.252160e-02 2.330300e-02
043-095(L01) 0.0 0.0 0.0 0.0 0.0 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000000 ... 13.308400 11.084000 9.514860 8.730070 7.958640e+00 7.249500e+00 6.697730e+00 6.278970e+00 6.019280e+00 5.670850e+00
043-097(L00) 0.0 0.0 0.0 0.0 0.0 1.379290e-07 5.388180e-06 1.827400e-07 8.016440e-07 0.005352 ... 0.000394 0.000228 0.000131 0.000087 4.040010e-05 6.121160e-06 1.084730e-06 6.949800e-07 1.232050e-07 1.013090e-07
sum 0.0 0.0 0.0 0.0 0.0 1.379313e-07 5.601885e-06 2.777680e-02 3.316308e-01 3.085918 ... 1080.658398 1079.959961 1087.902154 1097.773909 1.099505e+03 1.099857e+03 1.089266e+03 1.070388e+03 1.026290e+03 9.866779e+02
over NaN NaN NaN NaN NaN 0.000000e+00 0.000000e+00 0.000000e+00 0.000000e+00 0.000000 ... 0.012315 0.010263 0.008746 0.007953 7.238386e-03 6.591310e-03 6.148847e-03 5.866067e-03 5.865089e-03 5.747418e-03
我已经使用print(type(dict))
检查了数据框中的项目类型,并得到了<class 'pandas.core.frame.DataFrame'>
我尝试使用以下命令保存到csv:
for i in df_dict:
df_dict[i].to_csv[i]
这将返回错误:
IsADirectoryError: [Errno 21] Is a directory: '093nb-a'
任何帮助将不胜感激。谢谢
答案 0 :(得分:0)
您需要将文件名作为字符串传递给to_csv
函数,而不仅仅是数字。尝试这样做:
for i in df_dict:
df_dict[i].to_csv('dataframe_id_'+str(i)+'.csv')