Issue
I am trying to print the column data of a data frame as a string.
code:
df = pd.DataFrame({'I_like':['carrots','banana','watermelon']})
df =
I_like
0 carrots
1 banana
2 watermelon
Expected output:
col_as_string=
["carrots" or "banana" or "watermelon"]
Present code:
col_as_string = [ "\"%s or\""%(i) for i in df['I_like']]
col_as_string = ['"carrots or"', '"banana or"', '"watermelon or"']
Solution
Try with:
print('"{}"'.format('" or "'.join(df['I_like'])))
Output:
'"carrots" or "banana" or "watermelon"'
Answered By - Quang Hoang
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.