Quantcast
Channel: First steps - JuliaLang
Viewing all articles
Browse latest Browse all 2795

How to handle missing values in conditions

$
0
0

I have a dataframe with zeros and missing values and I would like to create an indicator array that assigns a one if the value is zero and a zero otherwise. I would like missing values to be included in this otherwise statement, meaning they should be assigned a zero too as they are not zero. I am unsure how to achieve this.

# Input
df = DataFrame(a = [0.0, missing, 3.0], b = [4.0, 5.0, 0.0])

# What I'm doing
not_zeros = .!iszero.(Matrix(df))
zeros = iszero.(Matrix(df))

# Desired Output 
not_zeros2 = [0, 1, 1 ; 1, 1, 0]
zeros2 = [1, 0, 0 ; 0, 0, 1]

4 posts - 3 participants

Read full topic


Viewing all articles
Browse latest Browse all 2795

Trending Articles