Python Forum
Extracting Rows From Data Frame and Understanding The Code - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Extracting Rows From Data Frame and Understanding The Code (/thread-28790.html)



Extracting Rows From Data Frame and Understanding The Code - JoeDainton123 - Aug-03-2020

Hello all

I have a data frame which i want to extract.

I am using the following code:-

Weekly_Report.iloc[:,0] == 75G2G2T8
I interpret this code as follows:-

From the selected data frame called Weekly Report.

I want all rows from the first column (which is indexed with 0) that equal 75G2G2T8

This gives me the following output:-
0 True
1 False
2 True
3 False
4 False

Where I have True then those rows equals my condition in that column.

This is where i need some help.

To get the actual rows of data that meet my condition i have been told to use the following code:-

Weekly_Report[Weekly_Report.iloc[:,0] == 75G2G2T8]
I dont understand why i need to put:-

Weekly_Report.iloc[:,0] == 75G2G2T8 
inside a set of square brackets with the name of the data frame Weekly_Report before it?

All i am doing, from my perspective, is passing in a list of True/False values and index numbers into the command:-

Weekly_Report[Index Values and True/False]
How does this extract the actual rows??

Can someone explain the code?

Can anyone help?

Thank you.