Is there a Python solution similar to R's nice solution below?
# R
set.seed(1245)
array_truth <- sample(c(T, F), 10, replace = T)
array_int <- 1:10
# get the integers with False index
> array_int[!array_truth]
[1] 1 2 4
In R, you can use !
to negate, but I haven't come across as nice a solution in Python:
# python
string_data = pd.Series(['aardvark', 'artichoke', np.nan, 'avocado'])
null_values = string_data.isnull()
null_values
0 False
1 False
2 True
3 False
dtype: bool
The most Pythonic solution I know of is:
string_data[null_values != True]
0 aardvark
1 artichoke
3 avocado
dtype: object
If this is the best I can do, that's great, but I'm new to Python and haven't seen this specific question anywhere.