data = pd.read_excel("data.xlsx",sheet_name="Sheet1",usecols=["year","code1","code2","name","keywords","type",'new'])
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
list= ['fund','year','inter','age','degree','title','institute','economy','gender','type']
for i in range(0,10):
print(data[list[i]].value_counts())
df_clear = data.drop(data[data['discipline']=="H"].index)
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)
结果:
','17340','http://www.zgglkx.com','2021','205')
DF','17340','http://www.zgglkx.com','2021',
template = "DF','17340','http://www.zgglkx.com','2021','205')"
res = re.findall(r"DF','(.*?)',",template)[0]
print(res)
结果:
17340
Process finished with exit code 0
import re
Pattern = re.compile(u'[\u4e00-\u9fa5]+')
key='[25] 张初兵,荣喜民.仿射利率模型下确定缴费型养老金的最优投资[J]. 系统工程理论与实践,2012,32(5):1048-1056. Zhang Chubing, Rong Ximin. Optimal investment for DC pension under the affineinterest rate model[J]. Systems Engineering-Theory & Practice, 2012, 32(5):1048-1056.'
match = Pattern.search(key)
if match:
print("存在中文")
在最后添加元素
list.append()
从最后删除元素
a = list.pop()
用#连接列表的元素
'#'.join(list[3:5])
def sum(*args):
a,b,c=args
d = a+b+c
print({f"The sum is {d}.")
输入:
sum(1,2,3)
输出:
The sum is 6.
age = input("how old qre you: ")
print("I am ",age,"years old")
结果:
how old are you: 2
I am 2 years old
Process finished with exit code 0
print('''
I
nned
money
''')
结果:
I
nned
money
Process finished with exit code 0
name = 10
height =100
print(f"I am {name} years old and I am {height} cm.")
name = 10
height =100
st = f"I am {name} years old and I am {height} cm."
print(st.format(name,height))
import re
str1 = '2020 第一卷 第五期'
str2 = re.sub(' +', ';', str1)
print(str2)
``
结果:
```python
2020;第一卷;第五期
string1 = string[0:string.rfind('[')]
string2 = string[string.rfind('[')+1:]
def ceil(*args, **kwargs): # real signature unknown
"""
Return the ceiling of x as an Integral.
This is the smallest integer >= x.
"""
pass
floor函数
返回小于等于函数的最大参数
def floor(*args, **kwargs): # real signature unknown
"""
Return the floor of x as an Integral.
This is the largest integer <= x.
"""
pass
data = data.loc[data["year"]==2016]
for i in range(2960):
data.loc[i,'author_num']=len(data.loc[i]['AU'].split(";"))
比if语句快很多很多
data['AP']=data.apply(lambda x:1 if x['DT'] == "Article; Proceedings Paper" else 0,axis=1)
data= data.drop(data[data['DT']=="Review"].index)
data['AP']=data.apply(lambda x:1 if x['DT'] == "Article; Proceedings Paper" else 0,axis=1)
data1= data1.dropna(axis=0,subset = ["ID_num"])
data1 = data1.drop(data1[data1['PG']>100].index)
data1 = data1.rename(columns={'Journal Impact Factor': 'JIF'})
data1['CY2'] = data1['CY2'].fillna(value = 0)
data1[["CY2"]] = data1[["CY2"]].astype(int)
data1 = data1.drop(data1.columns[[0,1]],axis=1)
data3 = pd.merge(data1,data2,on=['TC','JIF','PG','TI_num','Keywords','Ref_num','FU','SI','OA','Year'])
re.sub(r'\d',',',a)
\d就是找到字符串中的所有数字,a是待处理的字符串,中间的‘,’是想要替换成的内容