Pandas - Error inserting text column into Redshift table

六眼飞鱼酱① 提交于 2020-01-06 06:41:14

问题


I am trying to insert a text column of into a Redshift DB.

I get an error

DataError: value too long for type character varying(256)

Given below is the code I tried. The description column has text and the length goes upto 2000 characters.

Could anyone assist on how I could have this column inserted into the table.

 DF['description'] = DF['description'].str[:200].astype(str)

Could anyone assist, thanks.


回答1:


You should be using str.slice.

df['description'] = df['description'].str.slice(0,255)

Please note that this function works only in case of Strings or you may have to typecast.

Hope it helps.



来源:https://stackoverflow.com/questions/51175273/pandas-error-inserting-text-column-into-redshift-table

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