我要在字符串列中每个值的末尾添加“原始”,如果其中不包含单词raw。
from pandas import pandas as pd
df = pd.read_csv("files/Template_DataCatalogue_Test.csv", sep=";")
df.drop(df.index[3:], inplace=True)
df = df[~df["Title"].str.contains("raw"), "raw " + df["Title"].astype(str)]
print(df)
答案 0 :(得分:2)
df.loc[~df["Title"].str.contains("raw"), 'Title'] = "raw " + df["Title"].astype(str)
结束:
df.loc[~df["Title"].str.contains("raw"), 'Title'] = df["Title"].astype(str) + " raw"