I have a DataFrame as below which I received from hive DB.
How to extract value 'cat', 'animal', and 'dog' in column col2.
In[]:
sample = {'col1': ['cat', 'dog'], 'col2': ['WrappedArray([animal], [cat])', 'WrappedArray([animal], [dog])']}
df = pd.DataFrame(data=sample)
df
out[] :
col1 col2
-----------------------------------------
0 cat WrappedArray([animal], [cat])
1 dog WrappedArray([animal], [dog])
I tried to convert object to an array and extract the data like this code.
In[]: df['col2'][0][1]
Out[]: cat
If this is wrong, which way can I go for, I'm new to Pandas so the question might be unclear.
Thanks in advance.
WrappedArrayis spark type.