1 对dataframe的某一列用str处理后,其类型是<class 'pandas.core.strings.StringMethods'>.可以对df.['列名'].str直接进行切片操作.

如下实现了将df中某列的字符串分割,后生成新的df.用apply函数也可以实现如下功能,但非常慢.

参考:https://blog.csdn.net/yueyao121107/article/details/79730934

df = pd.DataFrame({'appid':['a00140327#a00170298#a00184278#a00187480',
'a00158535#a00163116#a00170432#a00187480#a00224345',
'a00109386#a00170432#a0021880#a00244790#a00247567',
'a00170298#a00203358#a00275200']})
df = df.head(2)
print(df)
# df = df['appid'].str.split('#', expand=True).stack().reset_index(level=1, drop=True)
df = df['appid'].str
df = df.split('#', expand=True) # 参数expand,这个参数取True时,会把切割出来的内容当做一列,产生多列,否则切换出来的是一个list
df = df.stack()
df = df.reset_index(level=1,drop=True) # 将索引的第一列置位普通列,并删除.
print(df)
print(type(df))
# appid
# 0 a00140327#a00170298#a00184278#a00187480
# 1 a00158535#a00163116#a00170432#a00187480#a00224345
# 0 a00140327
# 0 a00170298
# 0 a00184278
# 0 a00187480
# 1 a00158535
# 1 a00163116
# 1 a00170432
# 1 a00187480
# 1 a00224345
# dtype: object
# <class 'pandas.core.series.Series'>

Series.str方法的更多相关文章

  1. Series.str——字符串批量处理方法

    针对dataframe中的某一行(或列)想做批量字符串处理时,可采用此方法 series.str.python内置的str方法 例如: series.str.replace('A','B')   # ...

  2. str.方法的整理(字符串类型内置方法的具体使用)

    <1>str.strip().str.lstrip()和str.rstrip() 1' str.strip()(主要方法) 方法:str.strip(self,chars) 作用:移除字符 ...

  3. python str方法之ljust、rjust、center

    # -*- coding: cp936 -*- #python 27 #xiaodeng #str方法之ljust.rjust.center #http://www.runoob.com/python ...

  4. python repr方法和str方法

    每个类都有默认的__repr__, __str__方法,用print 实例时调用类的str方法,直接输出类的实例,调用的是类的repr方法 在命令行界面,不用print命令打印而是直接写变量名,就是用 ...

  5. Python之str方法

    # -*- coding: utf-8 -*- #python 27 #xiaodeng #Python之str方法 #http://python.jobbole.com/82655/ #str为一个 ...

  6. eval()方法与str()方法

    eval()方法与str()方法 #_author:Administrator#date:2019/10/31 a={ 'q':{'xxx':3456}}#将一个字典转换成一个字符串a=str(a)p ...

  7. Python 字典(Dictionary) str()方法

    Python 字典(Dictionary) str()方法 描述 Python 字典(Dictionary) str() 函数将值转化为适于人阅读的形式,以可打印的字符串表示.高佣联盟 www.cge ...

  8. Python str方法总结

    1.返回第一个字母大写 S.capitalize(...) S.capitalize() -> string 1 2 3 4 >>>a = 'shaw' >>> ...

  9. 【pandas】pandas.Series.str.split()---字符串分割

    原创博文,转载请注明出处! 本文代码的github地址       series中的元素均为字符串时,通过str.split可将字符串按指定的分隔符拆分成若干列的形式. 例子: 拆分以逗号为分隔符的字 ...

随机推荐

  1. 【 React - 1/100 】React绑定事件this指向问题--改变state中的值

    /** * 报错: * Cannot read property 'setState' of undefined * 原因: this指向不一致.btnAddCount中的this 和render中的 ...

  2. [转载]Quartus ii 一些Warning/Eeror分析与解决

    我会在此基础上继续添加 原文地址:ii 一些Warning/Eeror分析与解决">Quartus ii 一些Warning/Eeror分析与解决作者:yanppf 注:http:// ...

  3. 运用在伪类content上的html特殊字符

    原文转载于:https://www.cnblogs.com/wujindong/p/5630656.html 项目中用到的一些特殊字符和图标 html代码 <div class="cr ...

  4. Windows 实用软件

    Useful tool Listary Ditto Winsnap Quick Look Myper Splash GifCam ScreenToGif Free Download Manage Si ...

  5. tee 多重定向

    1.命令功能 tee读取标准输入的数据,并将内容输出成文件. 2.语法格式 tee  option  file tee  [-ai]  文件 参数说明 参数 参数说明 -a 追加到文件后面,非覆盖 - ...

  6. web框架-(三)Django进阶

    通过上节课的学习,我们已经对Django有了简单的了解,现在来深入了解下~ 1. 路由系统 1.1 单一路由对应 url(r'^index$', views.index), 1.2 基于正则的路由 u ...

  7. oracle汇编01

    1: / define numeric label "1"one: / define symbolic label "one"/ ... assembler c ...

  8. Linux下配置静态IP地址,设置DNS和主机名

    本人qq群也有许多的技术文档,希望可以为你提供一些帮助(非技术的勿加). QQ群:   281442983 (点击链接加入群:http://jq.qq.com/?_wv=1027&k=29Lo ...

  9. Thymeleaf 模板引擎简介

    目录 Thymeleaf 模板引擎 官方文档下载 Hello World 新建应用 后台控制器 前端页面 浏览器访问测试 Thymeleaf 模板引擎1.Thymeleaf 是 Web 和独立环境的现 ...

  10. 关于softmax稳定性问题

    因为softmax中指数函数,很容易超出计算机表达的最大值,所以采用分子分母同时乘N的方法,N一般为最大值.