【问题标题】:I want to delete values from a column corresponding to values starting with a particular string in another column我想从与以另一列中的特定字符串开头的值对应的列中删除值
【发布时间】:2020-08-15 04:31:13
【问题描述】:

删除标题为“LogKOW”的列中与标题为“CAS”的列中以 V-Mey_NA 开头的值相对应的值。

【问题讨论】:

标签: python pandas drop


【解决方案1】:

我想这会奏效

for index in df.index:
    if(df['CAS'][index].find('V-Mey_NA') != -1):
        df['LogKOW'][index] = np.nan

【讨论】:

  • 也许使用.startswith('V-Mey_NA')而不是.find('V-Mey_NA') != -1会更好。
  • 我这样做了,它成功了:(c = 0 for i in df['CAS']: c +=1 if i[0:8] == 'V-Mey_NA': df['LogKOW'][c] = np.NaN df)
【解决方案2】:

这可能有助于删除值

x = df1["CAS"].str.startswith("V-Mey_NA")
n = np.arange(0,1058,1)
df1.drop(n[x])

【讨论】:

    【解决方案3】:

    试试这个

    import numpy as np
    df['LogKOW'] = np.where(df.CAS.str.startswith('V-Mey_NA'),np.NaN,df['LogKOW'])
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-02
      • 2018-12-22
      • 2022-11-28
      • 1970-01-01
      • 2023-01-19
      • 1970-01-01
      相关资源
      最近更新 更多