11-17-2023 08:48 AM
Hello,
I have a single column dataframe and I want to transform the content into a string
EG df=
abc |
def |
xyz |
To
abc, def, xyz |
Thanks
11-20-2023 12:05 AM - edited 11-20-2023 12:17 AM
Hi @geertvanhove , You can use the df.tolist() method to convert your dataframe into a list, and then use the ', '.join() method to concatenate the elements of the list into a string.
Here's an example:
df = pd.DataFrame({'ABC': ['abc', 'def', 'xyz']})
result = ', '.join(df.tolist())
print(result) # Output: abc, def, XYZ
11-23-2023 06:45 AM
Hi @geertvanhove , you should apply the .tolist() function to a specific column or series within your DataFrame, rather than the entire DataFrame.
11-23-2023 07:01 AM
Thanks, but can you give me an example for this because following still gives me an error:
11-23-2023 06:00 AM
I get following error:
'DataFrame' object has no attribute 'tolist'
11-23-2023 06:05 AM
Hi @geertvanhove , Could you paste the code you're trying?
11-23-2023 06:24 AM
sure:
11-27-2023 12:08 AM
Hi @geertvanhove , I gave you the code with screenshot.