Search code examples
pythondataframefilteringdelete-rowdata-cleaning

How to filter particular string in column with Python?


I have a data set with a column contains STATE/UT names and also "Total" with state names.

Now i want to filter data with text contains %Total% and delete those rows (below is the screen shot) enter image description here

Can anyone suggest how to clean this?


Solution

  • for %TOTAL% use find

    df = pd.DataFrame({
        'STATE/UT': ['TOTAL(STATES)', 'TOTAL(UTs)', 'Normal'],
        'CRIME HEAD': ['RAPE', 'RAPE', 'RAPE']
    })
    df[df['STATE/UT'].str.find('TOTAL') == -1]