我尝试使用数据框架修改以python编写的前同事代码。
我们要从数据框“ df_msc”中删除所有不包含“已安装”列中“ drives_tup”字符串之一的行。他使用字符串修饰符“ startswith”和“ endswith”对其进行了修整,但是仍然通过不需要的行。有没有办法做类似string.isequalto(drives_tup)的事情?
我对python不太满意,所以我不想改变太多格式,因为我担心它会破坏代码的其他部分...
# Take only those drives where they start or end with one of the drives_tup values
drives_tup = ("/usr/asm", "/data/reserved", "/var", "/", "/data/diagnostics")
df_msc = df_msc.iloc[:, 1:-1].dropna(how='all')
df_msc = df_msc.loc[df_msc['Mounted'].str.startswith(drives_tup)]
df_msc = df_msc.loc[df_msc['Mounted'].str.endswith(drives_tup)]
答案 0 :(得分:1)
df_msc = df_msc.loc[df_msc['Mounted'].isin(drives_tup)]