操作方法 .str.
方法属性 s.str.lower() etc.
切分替换 .str.split('_').str.get(1) .str.replace('^.a|dog', 'XX-XX ', case=False)
连接 .str.cat(sep=',')
索引 s.str[0]
提取子串 .str.extract("(?P[a-zA-Z])")
1、数据类型
object 和 StringDtype 是 Pandas 的两个文本类型,不过作为新的数据类型,官方推荐 StringDtype 的使用
默认情况下,文本数据会被推断为 object 类型。
string 类型需要专门进行指定:

2、字符的操作
Series 和 Index 都用一些字符串处理方法,可以方便地进行操作,这些方法会自动排除丢失值和 NA 值。我们可以通过 str 属性访问它的方法,进行操作。





3、文本高级处理
对文本的分隔和替换是最常用的文本处理方式。对文本分隔后会生成一个列表,我们对列表进行切片操作,可以找到我们想要的内容,分隔后还可以将分隔内容展开,形成单独的行。












4、参考文献
《深入浅出Pandas》
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作! |