我想将python map(lambda x: a if condition1 else b, filter(lambda x: condition2, list1))
转换为pandas dict
。列数应等于特定键的值数。从下面的示例中,列名称应为dataframe
,i
,a
,b
和c
,其中d
是字典键并且其余是值:
i
答案 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')