如何将具有多个值的字典转换为pandas数据帧?

时间:2016-02-02 00:43:26

标签: python dictionary pandas

我想将python map(lambda x: a if condition1 else b, filter(lambda x: condition2, list1)) 转换为pandas dict。列数应等于特定键的值数。从下面的示例中,列名称应为dataframeiabc,其中d是字典键并且其余是值:

i

2 个答案:

答案 0 :(得分:1)

将字典直接转换为dataframe,然后转置它,因为需要交换行和列:

import pandas as pd
e_df = pd.DataFrame(e) 
e_df = e_df.T

答案 1 :(得分:0)

尝试.from_dict()

import pandas as pd
e = {}
for i in range(0, len("length_of_the_row")):
    e[i] = "a", "b", "c", "d"

df = pd.DataFrame.from_dict(e, orient='index')