How to Remove Rows from Pandas Data Frame that Contains any String in a Particular Column

后端 未结 4 772
轻奢々
轻奢々 2021-01-21 18:04

I have CSV data in the following format:

+-------------+-------------+-------+
|  Location   | Num of Reps | Sales |
+-------------+-------------+-------+
| 7589         


        
4条回答
  •  再見小時候
    2021-01-21 18:14

    You can use pd.to_numeric to coerce non numeric values to nan and then filter based on if the Location is nan:

    df[pd.to_numeric(df.Location, errors='coerce').notnull()]
    
    #Location  Num of Reps  Sales
    #0  75894            3     12
    #2  75286            7     24
    #4  27659            3     17
    

提交回复
热议问题