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

你可能感兴趣的:(Python知识补充)