大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。
Jetbrains全家桶1年46,售后保障稳定
今天在学习pandas的官方文档时,遇到了divmod这个函数,调用了help(divmod)。pandas返回了一行话如下:
divmod(x, y, /)
Return the tuple (x//y, x%y).
# 即x // y 返回的是x除以y以后的整数部分,
# x % y返回的是x 除以y后的余数部分
下面看一下,其在pandas中是如何使用的:
>>> s = pd.Series(np.arange(10))
>>> s
0 0
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
dtype: int32
# 返回结果是div,rem 即整数部分和余数
>>> div, rem = divmod(s, 3)
>>> div
0 0
1 0
2 0
3 1
4 1
5 1
6 2
7 2
8 2
9 3
dtype: int32
>>> rem
0 0
1 1
2 2
3 0
4 1
5 2
6 0
7 1
8 2
9 0
dtype: int32
哈哈,以上就是python小工具关于divmod的使用,有兴趣的话一起学习pandas
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/213457.html原文链接:https://javaforall.net