Converting pandas dataframe to structured arrays

后端 未结 3 1557
别跟我提以往
别跟我提以往 2021-01-17 02:03

I have the following pandas dataframe

import pandas as pd
a = [2.5,3.3]
b = [3.6,3.9]
D = {\'A\': a, \'B\': b}

which gives me

3条回答
  •  佛祖请我去吃肉
    2021-01-17 02:50

    np.rec.fromrecords(list(zip(df.melt().variable,df.melt().value)))
    Out[531]: 
    rec.array([('A',  2.5), ('A',  3.3), ('B',  3.6), ('B',  3.9)], 
              dtype=[('f0', '

提交回复
热议问题