I have a problem that is extension to this and this. Suppose I have dataframe like this:
A B
0 1 [["Thing_1"]]
1 2 [["Thing_1"], ["Thing_2"]]
2 3 [["Thing_1", "Thing_2"], ["Thing_2"]]
3 4 [["Thing_1"], ["Thing_1", "Thing_2"]]
4 5 [["Thing_1", "Thing_2"], ["Thing_1", "Thing_2"]]
Instead of getting like this:
A B C(result of length in column B)
0 1 [["Thing_1"]] 1
1 2 [["Thing_1"], ["Thing_2"]] 2
2 3 [["Thing_1", "Thing_2"], ["Thing_2"]] 2
3 4 [["Thing_1"], ["Thing_1", "Thing_2"]] 2
4 5 [["Thing_1", "Thing_2"], ["Thing_1", "Thing_2"]] 2
the column C becomes the length of the characters in the lists of lists rather than the outer length of lists of lists using these functions: df['B'].str.len()
and df['B'].apply(len)
. How can I get the result right?