私はあなたがリターンDataFrame
ためexpand=True
とstr.split
が必要だと思う:
history = pd.DataFrame({'message':['a - b','c - d - r']})
history[['a','b']] = history['message'].str.split(' - ', n=1, expand=True)
print (history)
message a b
0 a - b a b
1 c - d - r c d - r
何NaNs
使用した場合:私にとって
history[['a','b']] = pd.DataFrame([line.split(" - ", 1) for line in history['message']])
がエラーを返さない:
history['a'] = pd.DataFrame([line.split(" - ", 1) for line in history['message']])
print (history)
ValueError: Wrong number of items passed 2, placement implies 1
を
それはあなたのために働くのであれば、セパレーターをチェックしてみてください、split
がないようなので:
サンプル:
history['a'] = history['message'].str.split('^', n=1, expand=True)
print (history)
message a
0 a - b a - b
1 c - d - r c - d - r