[{"createTime":1735734952000,"id":1,"img":"hwy_ms_500_252.jpeg","link":"https://activity.huaweicloud.com/cps.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905","name":"华为云秒杀","status":9,"txt":"华为云38元秒杀","type":1,"updateTime":1735747411000,"userId":3},{"createTime":1736173885000,"id":2,"img":"txy_480_300.png","link":"https://cloud.tencent.com/act/cps/redirect?redirect=1077&cps_key=edb15096bfff75effaaa8c8bb66138bd&from=console","name":"腾讯云秒杀","status":9,"txt":"腾讯云限量秒杀","type":1,"updateTime":1736173885000,"userId":3},{"createTime":1736177492000,"id":3,"img":"aly_251_140.png","link":"https://www.aliyun.com/minisite/goods?userCode=pwp8kmv3","memo":"","name":"阿里云","status":9,"txt":"阿里云2折起","type":1,"updateTime":1736177492000,"userId":3},{"createTime":1735660800000,"id":4,"img":"vultr_560_300.png","link":"https://www.vultr.com/?ref=9603742-8H","name":"Vultr","status":9,"txt":"Vultr送$100","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":5,"img":"jdy_663_320.jpg","link":"https://3.cn/2ay1-e5t","name":"京东云","status":9,"txt":"京东云特惠专区","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":6,"img":"new_ads.png","link":"https://www.iodraw.com/ads","name":"发布广告","status":9,"txt":"发布广告","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":7,"img":"yun_910_50.png","link":"https://activity.huaweicloud.com/discount_area_v5/index.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=aXhpYW95YW5nOA===&utm_medium=cps&utm_campaign=201905","name":"底部","status":9,"txt":"高性能云服务器2折起","type":2,"updateTime":1735660800000,"userId":3}]
apply(func [, args [, kwargs ]])
函数用于当函数参数已经存在于一个元组或字典中时,间接地调用函数。args是一个包含将要提供给函数的按位置传递的参数的元组。如果省略了args,任
何参数都不会被传递,kwargs是一个包含关键字参数的字典。简单说apply()的返回值就是func()的返回值,apply()的元素参数是有序的,元素的顺序必须和func()形式参数的顺序一致,与map的区别是前者针对column,后者针对元素
lambda是匿名函数,即不再使用def的形式,可以简化脚本,使结构不冗余何简洁
a = lambda x : x + 1 a(10) 11
两者结合可以做很多很多事情,比如split在series里很多功能不可用,而index就可以做
比如有一串数据如下,要切分为总数,正确数,正确率,则可这样做
96%(1368608/1412722)
97%(1389916/1427922)
97%(1338695/1373803)
96%(1691941/1745196)
95%(1878802/1971608)
97%(944218/968845)
96%(1294939/1336576)
import pandas as pd #先生成一个dataframe d = {"col1" : ["96%(1368608/1412722)",
"97%(1389916/1427922)", "97%(1338695/1373803)", "96%(1691941/1745196)",
"95%(1878802/1971608)", "97%(944218/968845)", "96%(1294939/1336576)"]} df1 =
pd.DataFrame(d) #切分原文中识别率总数,采用apply + 匿名函数 #lambda 函数的意思是选取x的序列值 ,比如 x[6:9]
#index函数的意思是把当前字符位置转变为所在位置的位数 #-1是最后一位 df1['正确数'] = df1.iloc[:,0].apply(lambda
x : x[x.index('(') + 1 : x.index('/')]) df1['总数'] = df1.iloc[:,0].apply(lambda
x : x[x.index('/') + 1 : -1]) df1['正确率'] = df1.iloc[:,0].apply(lambda x :
x[:x.index('(')]) df1