python数据处理常用方法

1、读取指定sheet和指定列的内容

data = pd.read_excel("data.xlsx",sheet_name="Sheet1",usecols=["year","code1","code2","name","keywords","type",'new'])

 

2、遍历数据,对两列数据相似度比较

for i in range(0,75065):
    if data.loc[i]['code2']!=0:
        if data.loc[i]['code1'][:5]==data.loc[i]['code2'][:5]:
            data.loc[i,'inter']=0
        elif data.loc[i]['code1'][:3]==data.loc[i]['code2'][:3]:
            data.loc[i,'inter']=1
        elif data.loc[i]['code1'][:1]==data.loc[i]['code2'][:1]:
            data.loc[i,'inter']=2
        else:
            data.loc[i,'inter']=3

3、遍历数据,统计每类分类变量的数量

list= ['fund','year','inter','age','degree','title','institute','economy','gender','type']
for i in range(0,10):
    print(data[list[i]].value_counts())

4、遍历数据,删除某列为特定值的数据

df_clear = data.drop(data[data['discipline']=="H"].index)

5、正则去掉字符串左边或者右边的内容

import re
template = "DF','17340','http://www.zgglkx.com','2021','205')"

delete_left = template.lstrip('"DF')
print(delete_left)

delete_right = template.rstrip('205\')')
print(delete_right)

文章链接: https://www.mfisp.com/19221.html

文章标题:python数据处理常用方法

文章版权:梦飞科技所发布的内容,部分为原创文章,转载请注明来源,网络转载文章如有侵权请联系我们!

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

点点赞赏,手留余香

给TA打赏
共0人
还没有人赞赏,快来当第一个赞赏的人吧!
    建站教程

    服务器用什么Linux系统好

    2023-3-31 12:23:35

    建站教程

    python数据处理常用方法(二)

    2023-4-3 13:07:37

    0 条回复 A文章作者 M管理员
    如果喜欢,请评论一下~
    欢迎您,新朋友,感谢参与互动!
      暂无讨论,说说你的看法吧
    个人中心
    购物车
    优惠劵
    今日签到
    私信列表
    搜索

    梦飞科技 - 最新云主机促销服务器租用优惠

    可以介绍下你们的服务器产品么

    云服务器你们是怎么收费的呢

    租用vps现在有优惠活动吗