TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

Pandas Boolean indexing

Pandas Boolean indexing with What is Python Pandas, Reading Multiple Files, Null values, Multiple index, Application, Application Basics, Resampling, Plotting the data, Moving windows functions, Series, Read the file, Data operations, Filter Data etc.

<< Back to PANDAS

Boolean indexing

Boolean indexing is defined as a very important feature of numpy, which is frequently used in pandas. Its main task is to use the actual values of the data in the DataFrame. We can filter the data in the boolean indexing in different ways, which are as follows:

  • Access the DataFrame with a boolean index.
  • Apply the boolean mask to the DataFrame.
  • Masking the data based on column value.
  • Masking the data based on the index value.

Example1

This example shows the working of how to access the DataFrame with a boolean index:

# importing pandas as pd
import pandas as pd
# dictionary of lists 
dict = {'name':["Smith", "William", "Phill", "Parker"], 
        'age': ["28", "39", "34", "36"]} 
info = pd.DataFrame(dict, index = [True, True, False, True]) 
print(info)

Output:

name      age
True     Smith     28
True     William   39
False    Phill     34
True     Parker    36

Example2

This example shows the working of how to access the DataFrame with a boolean index by using .loc[]

# importing pandas as pd
import pandas as pd
# dictionary of lists 
dict = {'name':["Smith", "William", "Phill", "Parker"], 
        'age': ["28", "39", "34", "36"]} 
info = pd.DataFrame(dict, index = [True, True, False, True]) 
# accessing a dataframe using .loc[] function  
print(info.loc[True])

Output:

name    age
True   Smith     28
True   William   39
True   Parker    36

Next TopicConcatenating data




Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf