2017-03-07 11 views
1

私はintタイプのデータフレームの列を持っています。数字の列をデータフレームと組み合わせる

行のテキスト表現を保持する新しい列を作成したいとします。

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

私は私のテキスト生成機能とcasting to stringを追加することができますどのようにエラーTypeError: ('sequence item 1: expected string or Unicode, int found', u'occurred at index 0')

次取得していますか? astypeによってstr

答えて

2

てみキャスト:

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

または:

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