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

13、字符串的连接

name = 10
height =100
print(f"I am {name} years old and I am {height} cm.")

14、多个空格替换成其他符号

import re
str1 = '2020    第一卷         第五期'
str2 = re.sub(' +', ';', str1)
print(str2)
``
结果:
```python
2020;第一卷;第五期

15、获取某个字符串左边/右边的内容

string1 = string[0:string.rfind('[')]

string2 = string[string.rfind('[')+1:]

16、四舍五入和大小比较

def ceil(*args, **kwargs): # real signature unknown
    """
    Return the ceiling of x as an Integral.
    This is the smallest integer >= x.
    """
    pass

17、读取某列为指定内容的所有行

data = data.loc[data["year"]==2016]

18、统计作者数量并增加为新的列

for i in range(2960):
    data.loc[i,'author_num']=len(data.loc[i]['AU'].split(";"))

19、将某一列连续变量虚拟化

data['AP']=data.apply(lambda x:1 if x['DT'] == "Article; Proceedings Paper" else 0,axis=1)

20、删去某列为指定内容的行

data= data.drop(data[data['DT']=="Review"].index)

21、判断某列中每行的值,并且做出替代

data['AP']=data.apply(lambda x:1 if x['DT'] == "Article; Proceedings Paper" else 0,axis=1)

22、去掉某列中为空值的行

data1= data1.dropna(axis=0,subset = ["ID_num"]) 

 

 

 

 

 

 

 

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

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

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

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

给TA打赏
共{{data.count}}人
人已打赏
建站教程

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

2023-4-4 10:04:19

建站教程

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

2023-4-6 10:07:00

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
客户经理
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索

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