0

Im excluding rows from my df that fill certain conditions

df[~((df['Wood_type'] == 'pine') & (df['wood_size'] == 20))] 

I would like to also exclude, the numbers that start with 0 in the column 'Serial'

df[~((df['Wood_type'] == 'pine') & (df['wood_size'] == 20) & (df['Serial'] == range(0) == 0))]

I tried the above, no result.

Mad Physicist
  • 107,652
  • 25
  • 181
  • 264
Rexilife
  • 565
  • 1
  • 4
  • 7
  • How does a number start with zero? Is it actually a string? – Mad Physicist Jul 18 '19 at 21:16
  • would be a example: 0123.FX – Rexilife Jul 18 '19 at 21:18
  • Could you explain what do you imagine `df['Serial'] == range(0) ==0` does? – Mad Physicist Jul 18 '19 at 21:19
  • exclude rows where a value in column Serial, starts with number 0, like 0123.FX – Rexilife Jul 18 '19 at 21:28
  • Can you tell me how? Why are you using a `range` object? Are you aware of the implications of using two `==` in an expression? Finally, which part of that checks the first character in your string? – Mad Physicist Jul 18 '19 at 21:30
  • im not sure how, thats why i made this post. – Rexilife Jul 18 '19 at 21:32
  • I've noticed that you have not selected any answers to your other questions. You should consider going through, and giving answerers the credit they are due by clicking on the check marks. It helps their reputation and yours, and it's the right thing to do in this forum. – Mad Physicist Jul 18 '19 at 21:47
  • Possible duplicate of [pandas select from Dataframe using startswith](https://stackoverflow.com/questions/17957890/pandas-select-from-dataframe-using-startswith) – KenHBS Jul 18 '19 at 21:48

1 Answers1

0

You will probably want to use df.str.startswith to check the first character:

df[ ~((df['Wood_type'] == 'pine') & (df['wood_size'] == 20) & (df['Serial'].str.startswith('0')))]

The current expression df['Serial'] == range(0) == 0 is meaningless. It is equivalent to df['Serial'] == range(0) and range(0) == 0. Clearly, neither of those is related to comparing the first character of the string to '0' (as opposed to 0).

Mad Physicist
  • 107,652
  • 25
  • 181
  • 264