Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Slicing strings in a column in pandas

Tags:

python

pandas

csv

I have a CSV that has a column of URLs and I'm trying to slice out some unnecessary characters leading and trailing characters. I'm using the following syntax:

df.['column_name'].str[3:10]

Unfortunately I get TypeError: 'method' object is not subscriptable.

like image 723
KGBeans Avatar asked Aug 08 '16 20:08

KGBeans


1 Answers

pandas has a function to slice the entire column values, and is as follows:

df['column_name'].str.slice(start=3, stop=10)
like image 195
Jeril Avatar answered Nov 14 '22 23:11

Jeril