我是python的新手,在这里我需要一些帮助,请帮助我。 我有两个数据框,一个包含品牌名称,另一个是产品名称。在这里,我只想从数据框2中过滤数据框2中给定品牌列表的数据。
**brand_Name:
filter_value
0 Xiaomi
1 Celkon
2 Gionee
3 Asus
4 iBall
5 Karbonn
6 Lava
7 Lenovo
8 Micromax
9 Panasonic**
**New:**
****source_product_name source_product_id Status****
10 Redmi Y2 (Black, 32 GB) MOBFAANUCBGSRADJ New
18 Asus Zenfone Max Pro M1 (Black, 64 GB) MOBF4UQ9NSFFMH7Z New
21 Honor 9 Lite (Glacier Grey, 64 GB) MOBFF5ZGFJB78ZDB New
26 Redmi Y2 (Black, 32 GB) MOBFAANUCBGSRADJ New
34 Realme 3 (Radiant Blue, 32 GB) MOBFE68WHF6MZKG5 New
36 Realme 3 (Radiant Blue, 64 GB) MOBFE68WMCYD5SRT New
40 Honor 7A (Gold, 32 GB) MOBF3T87G3JWH667 New
41 Redmi Note 7 (Sapphire Blue, 32 GB) MOBFDXZ3TVHJFD8E New
46 Honor 9 Lite (Glacier Grey, 64 GB) MOBFF5ZGFJB78ZDB New
50 Redmi 6 (Blue, 32 GB) MOBF96CPQBJJHBGN New
57 Honor 10 Lite (Sapphire Blue, 32 GB) MOBFEMY3UZZUND2Z New
58 Redmi Y2 (Gold, 64 GB) MOBF7Y2DKUBEDUWH New
59 Vivo V9 Pro (Black, 64 GB) MOBFAFZZUHCXRFCF New
60 Panasonic Eluga Ray 530 (Blue, 32 GB) MOBFCMTFWGMSUA4H New
61 Redmi Note 5 Pro (Red, 64 GB) MOBF9JQUXSHWPFHC New
72 Honor 10 Lite (Sapphire Blue, 64 GB) MOBFCG2TH5GMGC26 New
75 Redmi 6A (Rose Gold, 32 GB) MOBFAMZB7HFYJUFX New
76 Redmi 6A (Rose Gold, 16 GB) MOBF9N2YPNCX2CP7 New
77 Nokia 5.1 Plus (Black, 64 GB) MOBFE3DUMGFKKHGR Ne
这些是我已经尝试过的东西
A = brandName.loc[brandName.filter_value.isin(New['source_product_id'])]
这里我得到一个空的数据框
New.assign(InbrandName=New.source_product_id.isin(brandName.filter_value).astype(int))
所有产品名称也只有零
New['status2'] = [
'donot keep' if brandName['filter_value'] not in
New['source_product_name'].tolist() else 'keep'
for brandName['filter_value'] in New['source_product_name']
]
abcd=New[New['status2']=='keep']
在这里,如果source_product_name包含特定品牌,我还将尝试打印多一列(保留/不保留)。