My data frame looks like this:
df = pd.DataFrame({'col1': [1, 2, 3 ,4 , 5, 6], 'txt': [[2354],[103, 132, 2457],[132, 1476, 6587],[103, 2457],[103, 1476, 2354], np.nan]})
col1 txt
0 1 [2354]
1 2 [103, 132, 2457]
2 3 [132, 1476, 6587]
3 4 [103, 2457]
4 5 [103, 1476, 2354]
5 6 NaN
Column 'txt' contains an array or NaN in each cell.
Now I would like to keep the dataframe structure as it is but the arrays should be a string containing all elements seperated by comma.
Required output (with string instead of array):
col1 txt
0 1 2354
1 2 103, 132, 2457
2 3 132, 1476, 6587
3 4 103, 2457
4 5 103, 1476, 2354
5 6 NaN
Solutions that I found did not work for a column.
Thank you.