Python crashes using pandas and str.strip

早过忘川 提交于 2019-12-06 04:08:13

You are doing a chained assignment which can behave in unexpected ways. see here: http://pandas.pydata.org/pandas-docs/dev/indexing.html#indexing-view-versus-copy. This is fixed in master and will work in 0.13.1 (coming soon). see here: https://github.com/pydata/pandas/pull/6031

This is not correct to do:

input_df['LL'].iloc[idx] = 3

Instead do:

input_df.ix[ix,'LL'] = 3

Or even better (as you are assigning ALL rows to 3)

input_df['LL'] = 3

If you are assigning just some of the rows (and have say an integer/boolean indexer)

input_df.ix[indexer,'LL'] = 3

You should also just do this to strip the whitespace:

input_df[col] = input_df[col].str.strip()
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!