How to convert tuple values to strings?

  • Python
  • Thread starter msn009
  • Start date
  • Tags
    python
  • #1
53
6

Main Question or Discussion Point

i have a column in a dataframe that contains values in the form or tuples (example: ('A',) ) and I want to convert these values to string format so that ('A',) becomes 'A'
How do I do this in python for a dataframe? Thanks.
 
Last edited by a moderator:

Answers and Replies

  • #2
11,501
5,052
There's str function which will print any instance in textual form which is great for debug but it might not be what you want.

To get the best results, you would need to loop over your tuples, extract the data and print it.
 
  • #3
wle
307
136
Python:
t = ('A', 'p', 'p', 'l', 'e')
''.join(t)   # returns 'Apple'
 
  • #4
53
6
thank you. in the end i decided to use a mapping method to convert the tuple values into a string format. it worked better for my situation
 

Related Threads on How to convert tuple values to strings?

  • Last Post
Replies
2
Views
3K
Replies
3
Views
474
Replies
4
Views
783
Replies
1
Views
11K
  • Last Post
Replies
5
Views
13K
Replies
1
Views
523
  • Last Post
Replies
15
Views
2K
Replies
3
Views
13K
Replies
9
Views
26K
Replies
6
Views
5K
Top