[英]Modify DataFrame based on another DataFrame in Pandas
我有這兩個數據框
df1
Product Quantity Price Description
0 bread 3 12 desc1
1 cookie 5 10 desc2
2 milk 7 15 desc3
3 sugar 4 7 desc4
4 chocolate 5 9 desc5
df2
Attribute Configuration
0 Product C
1 Quantity C
2 Price D
3 Description D
我想做的是如果字母D在df2的“ 配置”列中。 整行在df1中刪除。
所以df2就像用給我的配置來創建另一個數據幀的方式。
條件可能是...
if df2.Configuration == 'D'
df1.drop when df1.header = df2.Attribute
我有點提出這個想法,但我不確定是那樣的。 我可以做什么?
結果應該像這樣...
df3
Product Quantity
0 bread 3
1 cookie 5
2 milk 7
3 sugar 4
4 chocolate 5
運用
df1.drop(df2.loc[df2.Configuration=='D','Attribute'].tolist(),1)
Product Quantity
0 bread 3
1 cookie 5
2 milk 7
3 sugar 4
4 chocolate 5
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.