0

I want to remove rows which contains "True" in the column "aff".

Expected result : Wikipedia.org raw (line) is removed

My csv:

website;aff;cond;ger;azs
wikipedia.org;True;False;False;True
youtube.com;False;False;False;False
amazon.es;False;False;False;False

My code:

check = pd.read_csv(os.path.join(path2, "my.csv"), sep=";")
output = output.merge(check, on=["Domain"], how="left") 
output = output.loc[~(output["aff"] == "True")].reset_index(drop=True)

Print of output gives:

Domain            aff          cond      ger         azs
wikipedia.org     True         False     False       True
youtube.com       False        False     False       False
amazon.es         False        False     False       False

Print of output["aff"] gives:

0            True
1            False
2            False
3            False

2 Answers 2

1

I guess this is what you're looking for?

>>> !cat test.csv
website;aff;cond;ger;azs
wikipedia.org;True;False;False;True
youtube.com;False;False;False;False
amazon.es;False;False;False;False

>>> df=pd.read_csv('test.csv', sep=';')

>>> df

         website    aff   cond    ger    azs
0  wikipedia.org   True  False  False   True
1    youtube.com  False  False  False  False
2      amazon.es  False  False  False  False


>>> df[~df['aff']]

       website    aff   cond    ger    azs
1  youtube.com  False  False  False  False
2    amazon.es  False  False  False  False

I am only guessing here as there is no desired output posted, but based on your explanation - this should do it for you.

Sign up to request clarification or add additional context in comments.

5 Comments

Thx but it didn't help. I don't understand what's wrong with my code
can you elaborate please? Is that above not the desired output?If so - what is it?
Yes it is, but it's not working in my case
I succeed make it work only if it's a numerical value
I have amended my answer. This is literally all you need.
1

You put the Boolean value in quotations so it is comparing your values to a string, not the True value. Your method works without the quotes. In fact, it works without comparing the 'aff' series to a True value since you're working with booleans.

1 Comment

Thank, I've just realized that

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.