How to filter with Pandas

Hi together,

i’m working on a Data visualisation with Python. I did this before with VBA and i want to move my Project from VBA to Python. Very interesting challenge :slight_smile: .
I was wondering why after setting a Filter in Pandas i see only True/False values and not the whole Dataframe? I want to see everything to decide what i need for my futher analyses and what is missing.

This is my Filter so far:

my_Filter = df[‘Calendar_Week’] == 45
print(my_Filter)

As a result i see only the rows with True/False:

0 True
1 True
2 True
3 True

But no Data? I want to see the DataFrame like before.

What i need to do?

Thanks,
Simo

my_Filter = df [df[‘Calendar_Week’] == 45]
print(my_Filter)

df[‘Calendar_Week’] == 45 this will create a boolean version of dataframe. Apply this boolean mask to the dataframe again to see the values corresponding to True value.

Check out this link for more info

Hi @jithins123 thanks for your fast reply.
With add to the DataFrame again you mean like:

df = df[‘Calendar_Week’] == 45?

When i try to add the DataFrame to a variable a get an error message and this is very strange:

File “”, line 5
new = df[‘Calendar_Week’] == 45
^
SyntaxError: invalid character in identifier

Thanks.

Have you tried this?

1 Like

Hi @jithins123, now it works.
I had a copy&paste error or something like this.
Instead of a " ’ " i had a " ` " in my Filter.
Thats why Jupyter didn’t accept my statement.

Thanks for your support, now I can go ahead :slight_smile: !

Awesome. Please note that next time while asking questions, do follow this guidelines for better assistance.