I have a dataframe in pandas and one of my columns is a set of lists; however, some of the lists in the column have more elements than others:
df['Name'].head()
Output:
0 ['Andrew', '24']
1 ['James']
2 ['Billy', '19', 'M']
3 ['Grace', '42']
4 ['Amy']
Is it possible for me to concatenate each element in each list together, while still maintaining my df?
Desired output:
0 'Andrew24'
1 'James'
2 'Billy19M'
3 'Grace42'
4 'Amy'
I tried many different things; the closest I got was using the snip below but this concatenated all of the lists together in each record:
def concatenate_list_data(list):
result= ''
for element in list:
result += str(element)
return result
df['Name'] = concatenate_list_data(df['Name'])`