简体   繁体   中英

How do I search for specific text in a string using python

I am using this dataset to try and make a dynamic bubble graph but I came across an issue. When I search for the genre eg Western it searches for exactly that string. The problem is that 'dataset_by_year["genre"]' holds genres with multiple genres (eg western, comedy, action), which is not matched.

for genre in genres:
    dataset_by_year = BubbleGV[BubbleGV["year"] == year1]
    dataset_by_year_and_cont = dataset_by_year[
        dataset_by_year["genre"] == genre]

All I want to do is to search for the genre within the multiple genres and match the string.

Any help would be greatly appreciated.

抱歉没有检查你的完整数据试试这个,它可能有效:

dataset_by_year_and_cont = dataset_by_year[dataset_by_year["genre"].str.contains(genre)]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM