w3resource

Pandas Excel: Find all records that include two specific MSHA ID


13. Find Records with Two Specific MSHA IDs

Write a Pandas program to import given excel data (coalpublic2013.xls ) into a dataframe and find all records that include two specific MSHA ID. Go to Excel data

Sample Solution:

Python Code :

import pandas as pd
import numpy as np
df = pd.read_excel('E:\coalpublic2013.xlsx')    
df[df["MSHA ID"].isin([102976,103380])].head()

Sample Output:

    Year  MSHA ID                      Mine_Name  Production  Labor_Hours
18  2013   102976  Piney Woods Preparation Plant           0        14828
19  2013   102976  Piney Woods Preparation Plant           0        23193
20  2013   103380                         Calera           0        12621
21  2013   103380                         Calera           0         1402	                                       

Excel Data:

coalpublic2013.xlsx:



For more Practice: Solve these Related Problems:

  • Write a Pandas program to import coalpublic2013.xlsx and filter records that include two given MSHA IDs using isin().
  • Write a Pandas program to select rows where the MSHA ID is either of two specified values and display the result.
  • Write a Pandas program to filter the DataFrame by a list containing two specific MSHA IDs and print matching records.
  • Write a Pandas program to use boolean indexing with multiple conditions to extract records that have either of two MSHA IDs.

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a Pandas program to import given excel data (coalpublic2013.xlsx ) into a dataframe and find details where "Mine Name" starts with "P".
Next: Write a Pandas program to import given excel data (coalpublic2013.xlsx ) into a Pandas dataframe and find a list of specified customers by name.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.