python - Pandas: get second character of the string, from every row -
i've array of data in pandas , i'm trying print second character of every string in col1. can't figure out how it. can print second character of each string individually, example:
array.col1[0][1]
however i'd print second character every row, there "list" of second characters.
i've tried
array.col1[0:][1]
but returns second line whole of col1.
any advice?
you can use str
access string methods column/series , slice strings normal:
>>> df = pd.dataframe(['foo', 'bar', 'baz'], columns=['col1']) >>> df col1 0 foo 1 bar 2 baz >>> df.col1.str[1] 0 o 1 2
this str
attribute gives access variety of useful vectorised string methods, many of instantly recognisable python's own assortment of built-in string methods (split
, replace
, etc.).
Comments
Post a Comment