擅长:python、mysql、java
<p>首先,您可以生成字典列表的所有值,然后传递给<code>DataFrame</code>构造函数,最后一次连接到原始:</p>
<pre><code>L = [[{'matched_ingredient_id': 'U030100',
'matched_ingredient_st': 'Kalb',
},
{ 'matched_ingredient_id': 'U030100',
'matched_ingredient_st': 'Ka',
'splitted_ingredient': 'Zwiebel(n)'}],[
{'matched_ingredient_id': 'U030100',
'matched_ingredient_st': 'roh',
},
{ 'matched_ingredient_id': 'U030100',
'matched_ingredient_st': 'K',
'splitted_ingredient': 'Zwiebel'}
]]
df = pd.DataFrame({'parsed_ingredients':L})
</code></pre>
<hr/>
<pre><code>L = [{y['matched_ingredient_st']:1 for y in x if not y["matched_ingredient_st"] == "None"}
for x in df['parsed_ingredients']]
df1 = pd.DataFrame(L, index=df.index).fillna(0).astype(int)
print (df1)
Kalb Ka roh K
0 1 1 0 0
1 0 0 1 1
df = df.join(df1)
print(df)
parsed_ingredients Kalb Ka roh K
0 [{'matched_ingredient_id': 'U030100', 'matched... 1 1 0 0
1 [{'matched_ingredient_id': 'U030100', 'matched... 0 0 1 1
</code></pre>