Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I combine multiple text filled rows into one in Python? [closed]

Tags:

python

So I have like 20,000 rows in a single column in Excel that contains all text. I'm trying to combine all the rows into a single cell that I call 'message' so then I can do some stuff in TextBlob, like count the number of sentences, but I'm not having any success combining all the text rows into one.

input (cant seem to copy and paste but formatted as a single column)

MsgBody
sure can
race game 
like one of the biggest games

desired output:

sure can, race game, like one of the biggest games

actual output:

sure can
import csv
from textblob import TextBlob
import pandas as pd

input_csv = pd.read_csv(r'output.csv')
messages = input_csv['MsgBody']

allMessages = []

for message in messages:
    allMessages.append(message)
like image 210
Lauren Avatar asked Feb 21 '26 17:02

Lauren


1 Answers

With the full spec now, it seems you just want:

', '.join(messages)

This will take the array and transform it into a single comma-separated string.

PS: The copy-paste credit posting thing is an April Fool that seems rather counterproductive.

like image 60
Ken Y-N Avatar answered Feb 24 '26 07:02

Ken Y-N



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!