vaccines_by_Beijing=vaccines_by_country[vaccines_by_country['vaccines']=='Sinopharm/Beijing'] vaccines_by_Wuhan=vaccines_by_country[vaccines_by_country['vaccines']=='Sinopharm/Wuhan'] vaccines_by_Sinovac=vaccines_by_country[vaccines_by_country['vaccines']=='Sinovac'] vaccines_by_China_0 = vaccines_by_Beijing.append(vaccines_by_Wuhan) vaccines_by_China = vaccines_by_China_0.append(vaccines_by_Sinovac) 以上的代码能否换个方式实现其功能
时间: 2024-02-03 20:01:43 浏览: 67
可以使用 Pandas 的 loc 方法来实现上述代码的功能,示例代码如下:
```
vaccines_by_China = vaccines_by_country.loc[vaccines_by_country['vaccines'].str.contains('Sinopharm/Beijing|Sinopharm/Wuhan|Sinovac')]
```
这行代码会筛选出疫苗名称包含 "Sinopharm/Beijing"、"Sinopharm/Wuhan"、"Sinovac" 的行,并将其赋值给变量 vaccines_by_China。
阅读全文