Python知识补充

1.Python中的str.contains()类似于SQL中的like,在数据处理中非常常用
例:


详细解释:https://www.jianshu.com/p/805f20ac6e06

2.split()函数
Python中有split()和os.path.split()两个函数,具体作用如下:
split():拆分字符串。通过指定分隔符对字符串进行切片,并返回分割后的字符串列表(list)
os.path.split():按照路径将文件名和路径分割开
例:

str="hello boy<[www.baidu.com]>byebye"

print(str.split("[")[1].split("]")[0])

www.baidu.com

详细解释: https://blog.csdn.net/orangefly0214/article/details/80810449
3.iterrows()、itertuples()、iteritems()的用法
iterrows(): 将DataFrame迭代为(insex, Series)对。
itertuples(): 将DataFrame迭代为元祖。
iteritems(): 将DataFrame迭代为(列名, Series)对
详细解释:https://www.jianshu.com/p/31f6c13df90f
4.update()函数用法

# !/usr/bin/python3
 
D = {'one': 1, 'two': 2}
 
D.update({'three': 3, 'four': 4})  # 传一个字典
print(D)
 
D.update(five=5, six=6)  # 传关键字
print(D)
 
D.update([('seven', 7), ('eight', 8)])  # 传一个包含一个或多个元祖的列表
print(D)
 
D.update(zip(['eleven', 'twelve'], [11, 12]))  # 传一个zip()函数
print(D)
 
D.update(one=111, two=222)  # 使用以上任意方法修改存在的键对应的值
print(D)
以上实例输出结果为:
{'one': 1, 'three': 3, 'two': 2, 'four': 4}
{'one': 1, 'four': 4, 'six': 6, 'two': 2, 'five': 5, 'three': 3}
{'one': 1, 'eight': 8, 'seven': 7, 'four': 4, 'six': 6, 'two': 2, 'five': 5, 'three': 3}
{'one': 1, 'eight': 8, 'seven': 7, 'four': 4, 'eleven': 11, 'six': 6, 'twelve': 12, 'two': 2, 'five': 5, 'three': 3}
{'four': 4, 'seven': 7, 'twelve': 12, 'six': 6, 'eleven': 11, 'three': 3, 'one': 111, 'eight': 8, 'two': 222, 'five': 5}

4.drop_duplicates()去重(又忘了,这个学了很多遍的)
5.stack()和unstack()的用法
其实我理解的就是columns 和index的相互转换
详细解释:https://www.jianshu.com/p/5ab1019836c9

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 写了个程序,对Pandas的绝大部分函数及其说明进行了中文翻译。原网址:http://pandas.pydata....
    TSIANG阅读 10,996评论 0 4
  • Pandas-9. 迭代 Pandas对象之间的底本迭代的行为取决于类型,当迭代一个Series时,它被视为数组,...
    悠扬前奏阅读 3,762评论 0 0
  • 数据转换 :str、int、float、tuple、list,dict 1. List 列表 支持字符、数字、字符...
    李的读书观影笔记阅读 3,875评论 0 0
  • 久违的晴天,家长会。 家长大会开好到教室时,离放学已经没多少时间了。班主任说已经安排了三个家长分享经验。 放学铃声...
    飘雪儿5阅读 12,218评论 16 22
  • 创业是很多人的梦想,多少人为了理想和不甘选择了创业来实现自我价值,我就是其中一个。 创业后,我由女人变成了超人,什...
    亦宝宝阅读 5,865评论 4 1

友情链接更多精彩内容