python dict to numpy structured array

前端 未结 5 475
星月不相逢
星月不相逢 2020-12-02 12:04

I have a dictionary that I need to convert to a NumPy structured array. I\'m using the arcpy function NumPyArraytoTable, so a NumPy structured array is the only data format

5条回答
  •  执笔经年
    2020-12-02 12:48

    Even more simple if you accept using pandas :

    import pandas
    result = {0: 1.1181753789488595, 1: 0.5566080288678394, 2: 0.4718269778030734, 3: 0.48716683119447185, 4: 1.0, 5: 0.1395076201641266, 6: 0.20941558441558442}
    df = pandas.DataFrame(result, index=[0])
    print df
    

    gives :

              0         1         2         3  4         5         6
    0  1.118175  0.556608  0.471827  0.487167  1  0.139508  0.209416
    

提交回复
热议问题