I have a dataframe with missing values. How can I write either a python or an R code to replace empty spaces with 0, a single string with 1, and multiple strings joined by "\t" with a number corresponding to how many "\t"s + 1.
my data frame:
col1 col2 col3
row1 5blue 2green5 white
row2 white green\twhite3\t3blue5
row3 blue3 white
row4 7blue green2
row5 3green 3white6
row6 6blue green\t6white7 green
row7 5blue5 6green white
row8 blue6
Output expected:
col1 col2 col3
row1 1 1 1
row2 0 1 3
row3 1 0 1
row4 1 1 0
row5 0 1 1
row6 1 2 1
row7 1 1 1
row8 1 0 0
Any ideas? Thanks