I want to concatenate two rows in a DataFrame into one row. My current code:
import pandas as pd
df = pd.DataFrame(columns = ['string1', 'string2'])
df.loc[len(df), :] = ['Hello', 'This is Sam']
df.loc[len(df), :] = ['how are you?', 'from Canada']
#create the next row: ['Hello how are you?', 'This is Sam from Canada']
How to do it?
You can test the code here.
string1column between rows 1 and 2, e.g. 'This is Sam' + 'from Canada'. That's concatenating columns not rows, and it's string-concatenation (multiple strings into one string, not the usual concatenating multiple rows into one dataframe containing multiple rows).