python中字符串与数据帧的匹配

2024-04-25 15:18:40 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个列表如下

listvalue = ["POS 541919XXXXXX5316 WWW PAYTM COM POS DEBIT","POS 541919XXXXXX5316        HASBRO CLOTHING POS DEBIT","Salary for the month of April 2018"]

我有一个数据帧,如下所示:

           variable                   value
0          ATM Cash                 withdrawal
8       Auto & Fuel                    fuel
16          Expense                    fees
17          Expense                    goods
18          Expense                 stationery
19          Expense                  purchase
20          Expense                  material
21          Expense                 telephone
24  Food/Restaurent                   food
25  Food/Restaurent                  catering
32          General                  others
40        Groceries                  big bazar
48           Income                   salary
49           Income                 deposit
50           Income                  rewards
56          Medical                    dr
57          Medical                   doctor
58          Medical                    dr.
59          Medical                  nursing
60          Medical                pharmacist
61          Medical                 physician
62          Medical                 hospital
63          Medical                  medicine
64  Mobile recharge                 airtel
72          Payment                 tranfer
73          Payment                payment
80         Shopping                 cloths
81         Shopping               clothing
88           Travel                 travel

我必须比较value dataframe中的每个listvalue。如果listvalue中dataframe中有任何值的字,我想打印该值的变量。你知道吗


Tags: posdataframe列表foodvaluewwwpaymentmedical
1条回答
网友
1楼 · 发布于 2024-04-25 15:18:40

也许你的意思是这样的:

words = ' '.join(listvalue).upper().split()
idx = df.value.str.upper().isin(words)

In: df[idx]
Out: 
    variable     value
48    Income    salary
81  Shopping  clothing

相关问题 更多 >

    热门问题