Remove the values in column titled “LogKOW” corresponding to the values starting with V-Mey_NA in the column titled “CAS”.
Asked
Active
Viewed 226 times
-4
-
2Welcome to StackOverflow. Please take the time to read this post on [how to provide a great pandas example](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) as well as how to provide a [minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve) and revise your question accordingly. These tips on how to ask a good question may also be useful. – yatu Apr 30 '20 at 17:53
-
Please provide some sample data. – Sajan Apr 30 '20 at 18:04
-
https://archive.ics.uci.edu/ml/machine-learning-databases/00511/ – Prabal Bali Apr 30 '20 at 18:36
3 Answers
0
I guess this will work
for index in df.index:
if(df['CAS'][index].find('V-Mey_NA') != -1):
df['LogKOW'][index] = np.nan
-
Maybe it would be better to use `.startswith('V-Mey_NA')` instead of `.find('V-Mey_NA') != -1`. – Gilles D. May 02 '20 at 12:17
-
I did this and it worked: `(c = 0 for i in df['CAS']: c +=1 if i[0:8] == 'V-Mey_NA': df['LogKOW'][c] = np.NaN df)` – Prabal Bali May 03 '20 at 10:34
0
This might help in removing the values
x = df1["CAS"].str.startswith("V-Mey_NA")
n = np.arange(0,1058,1)
df1.drop(n[x])

David Buck
- 3,752
- 35
- 31
- 35
0
Try this instead
import numpy as np
df['LogKOW'] = np.where(df.CAS.str.startswith('V-Mey_NA'),np.NaN,df['LogKOW'])

Kartik Singhal
- 11
- 2