Skip to content
Advertisement

export a comma-separated string as a text file without auto-formatting it as a CSV

Im developing an API which should, ideally, export a conmma-separated list as a .txt file which should look like

alphanumeric1, alphanumeric2, alphanumeric3

the data to be exported is coming from a column of a pandas dataframe, so I guess I get it, but all my attempts to get it as a single-line string literal havent worked. Instead, the text file I receive is

,ColumnHeader
0,alphanumeric1
0,alphanumeric2
0,alphanumeric3

I’ve tried using string literals with the backticks, writing to multiple lines, appending commas to each value in the list, but it all comes out in the form of a csv, which wont work for my purposes.

How would yall achieve this effect?

Advertisement

Answer

I am not sure if what you need is:

csvList = ','.join(df.ColumnHeader)

where, df is of course your pandas dataframe

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement