【发布时间】:2021-12-25 12:10:40
【问题描述】:
我的示例 DataFrame 是:
| file | Voucher_stand |
|---|---|
| 90.txt | SCA |
| 90.txt | SCB |
| 60.txt | WFA |
| 60.txt | WFO |
| 90.txt | SCA |
| 50.txt | SCA |
| 80.txt | SCA |
| 100.txt | SCA |
我想定义一个字典,根据它我可以选择一些列,但是每个文件在 Voucher_stand 列中都有自己的代码,如何根据 Voucher_stand 和文件通过字典过滤这个 DataFrame 而不是每次都使用列表?
例如,在字典中定义 Voucher_Stand 和文件,然后根据该字典过滤我的 DataFrame:
code = {'90.txt':['SCA', 'SCB'], '60.txt':['WFA', 'WFO']}
【问题讨论】:
标签: python pandas dataframe dictionary