我有以下数据:
Parent_Attribute Attribute Y/N for Modelling Impute_Value Type Product Description
age age YES Unknown CAT Multiple ecohorts
bill_other bill_other_m0 YES 0 CAT Multiple Billing (other)
bill_other bill_other_m1 YES 0 CAT Multiple Billing (other)
bill_other bill_other_m2 YES 0 CAT Multiple Billing (other)
bill_other bill_other_m3 YES 0 CAT Multiple Billing (other)
bill_other bill_other_m4 YES 0 CAT Multiple Billing (other)所有这些都需要存储在字典中,其中属性是键,其余的列值作为键的值:
attribute : ['parent_attribute,Y/N Modelling,Impute_Value,Type,Product,Description] 这必须对dataframe的每一行执行。
完整的字典会看上去像。
{
age :['age',"Yes","Unknown","CAT","Multiple","ecohorts"]
bill_other_m0 :["bill_other","Yes",0,"CAT","Multiple","Billing(Other)"]
bill_other_m1 :["bill_other","Yes",0,"CAT","Multiple","Billing(Other)"]
bill_other_m2 :["bill_other","Yes",0,"CAT","Multiple","Billing(Other)"]
bill_other_m3 :["bill_other","Yes",0,"CAT","Multiple","Billing(Other)"]
bill_other_m4 :["bill_other","Yes",0,"CAT","Multiple","Billing(Other)"]
}我通过了dataframe.to_dict,但它似乎不像是只使用它将有助于我的目的。有人能指点我吗?
发布于 2018-04-05 07:02:50
看来有必要:
d = df.set_index('Attribute').T.to_dict('l')https://stackoverflow.com/questions/49665984
复制相似问题