Pandas - Error inserting text column into Redshift

2019-08-27 22:07发布

问题:

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.