2017-03-07 5 views
1

Ich habe int Typ Spalten mit Dataframe.Kombinieren von numerischen Spalten mit Datenrahmen

Ich möchte eine neue Spalte erstellen, die Textdarstellung der Zeile enthält.

df['text'] = df[['project', 'from', 'to', 'score']].apply(lambda x: '_'.join(x), axis=1) 

Ich erhalte Fehler folgende TypeError: ('sequence item 1: expected string or Unicode, int found', u'occurred at index 0')

Wie ich casting to string mit meiner Textgenerierung Funktion hinzufügen kann?

Antwort

2

Try cast str von astype:

df['text'] = df[['project', 'from', 'to', 'score']] 
       .apply(lambda x: '_'.join(x.astype(str)), axis=1) 

Oder:

df['text'] = df[['project', 'from', 'to', 'score']] 
       .astype(str) 
       .apply(lambda x: '_'.join(x), axis=1) 
Verwandte Themen