How to convert a Pandas data frame dictionary to comma-separated string?
products = df.T.to_dict().values()
Example data print(f"{product.items()}")
:
dict_items([('Category', 'My Category'), ('Title', 'My Title'), ('Catalouge Reference Number/SKU', 'abc123'), ('countryOfOrigin', 'usa'), ('generalDescription', '0.0'), ('Lead Time', '10')])
CodePudding user response:
Use built-in .to_csv()
function:
str_repr = df.to_csv(index=False)
CodePudding user response:
You can select first row of DataFrame and join values in list comprehension:
L = [':'.join(x) for x in df.iloc[0].items()]