0

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?

hc_dev
  • 8,389
  • 1
  • 26
  • 38
Sriram K
  • 21
  • 5
  • Welcome to stack overflow. Please [edit] your question to include a [mcve] with sample input, expected output, and _code_ for what you've already tried based on your own research. See [How to make good pandas examples](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) also – G. Anderson Jan 04 '22 at 17:51

2 Answers2

0

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
Romain
  • 19,910
  • 6
  • 56
  • 65
0

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']
stefanJonB
  • 60
  • 5