Have the value 'Select' in various columns of a data frame. This value is as good as a NaN value, so the same needs to be dropped.
When checking the contents of a Column - Specialisation the following is what is displayed:
0 Select
1 Select
2 Business Administration
3 Media and Advertising
4 Select
...
9235 IT Projects Management
9236 Media and Advertising
9237 Business Administration
9238 Human Resource Management
Similar value 'Select' is available in various columns which need to be dropped.
What code can be used?
CodePudding user response:
You can apply a bolean mask to only get the row which does not contains 'Select'. The following code should work once adapted to your dataframe
df[df["name_of_the_column"] != 'Select']
CodePudding user response:
If "Select" can be considered as NaN you can replace it by pd.NA everywhere and then drop it as you want by using dropna.
df = pd.DataFrame({'0': {0: 1, 1: 2, 2: 3, 3: 4},
'Select': {0: 'Select',
1: 'Business Administration',
2: 'Media and Advertising',
3: 'Select'}})
df.replace("Select", pd.NA).dropna()
# 0 Select
# -- --- -----------------------
# 1 2 Business Administration
# 2 3 Media and Advertising
