strong text我试图通过以特定的方式格式化每一列来修改数据帧:我的问题是,当我尝试使用某些条件格式化特定列时,我似乎无法做到这一点。更具体地说,这里是我的3个条件:
我试过用.iterrows()
,itertuple()
,甚至.apply()
但是似乎什么都不管用。。。先谢谢你
输入df
[某物]|[某物]| http://www.w3.org/2002/07/owl#Class|
[某物]|[某物]|某物的一部分|
[某物]|[某物]| http://oaei.ontologymatching.org/tests/101/onto.rdf#R|
预期产量
[某物]|[某物]|猫头鹰:类|
[某物]|[某物]|“某物的一部分”@en|
[某物]|[某物]|<__http://oaei.ontologymatch.org/tests/101/onto.rdf#参考>;|
这是我的密码:
def to_turtle(df):
df['subject'] = '<' + df['subject'] + '>'
df['predicate'] = '<' + df['predicate'] + '>'
for row in df.itertuples():
if df.loc[row.Index,'object'].str.startswith('http://o', na=False):
df.at[row.Index, 'object'] = "<" + df['object'] + "> ;"
elif df.loc[row.Index,'object'].str.contains('[A-Z]',na=False,regex=True):
df.at[row.Index, 'object'] = '"' + df['object'] + '"@en .'
else:
df.at[row.Index, 'object'] = df['object'].str.replace('http://www.w3.org/2002/07/owl#Class', 'owl:Class')
ont1 = pd.read_csv('1.tsv',sep='\t',names=['subject','predicate','object'])
目前没有回答
相关问题 更多 >
编程相关推荐