how to drop the str “Pandas” and the key name in the tuple when using to_csv?

I have a DataFrame like the below, and I get the df by using DataFrame.itertuples() function

    columnName                   
0   (CJ, 2, 1.0, 31, 34.46)
1   (CJ, 2, 1.0, 31, 34.46)
2   (CJ, 2, 1.0, 31, 34.46)

when I use the to_csv() function, I get the csv file like this:

   columnName
0  Pandas(Index='CJ', position=2, pos_options=1.0, salary=31, Value=34.46)
1  Pandas(Index='CJ', position=2, pos_options=1.0, salary=31, Value=34.46)
2  Pandas(Index='CJ', position=2, pos_options=1.0, salary=31, Value=34.46)

how can I dorp the annoying “Pandas” ,”index=”,”position=”, “pos_options=”,”salary=”, “Value=”? They are filled with the csv table and affect the human reading.

what I want is the simple expressions like this:

    columnName                   
0   CJ, 2, 1.0, 31, 34.46
1   CJ, 2, 1.0, 31, 34.46
2   CJ, 2, 1.0, 31, 34.46

Answer

You can use strip() method:

df['columnName']=df['columnName'].astype(str).str.strip('()')

Now if you print df you will get:

    columnName
0   'CJ', 2, 1.0, 31, 34.46
1   'CJ', 2, 1.0, 31, 34.46
2   'CJ', 2, 1.0, 31, 34.46

EDIT: If you have many columns then use apply() method:

df=df.apply(lambda x:x.astype(str).str.strip('()'),1)

Finally use to_csv() method

df.to_csv('filename.csv')