w3resource

Pandas Excel: Find a specific MSHA ID


10. Find Specific MSHA ID

Write a Pandas program to import given excel data (coalpublic2013.xls ) into a dataframe and find a 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"]==102901].head()

Sample Output:

   Year  MSHA ID         Mine_Name  Production  Labor_Hours
8  2013   102901  Shoal Creek Mine           0        12396
9  2013   102901  Shoal Creek Mine     1453024      1237415	                                       

Excel Data:

coalpublic2013.xlsx:



For more Practice: Solve these Related Problems:

  • Write a Pandas program to import coalpublic2013.xlsx and search for a row with a specific MSHA ID.
  • Write a Pandas program to filter the DataFrame for a given MSHA ID and display all associated records.
  • Write a Pandas program to use query() on the imported Excel data to find a record matching a specific MSHA ID.
  • Write a Pandas program to locate and print details of a specific MSHA ID from the DataFrame using boolean indexing.

Go to:


Previous: Write a Pandas program to create a subtotal of "Labor Hours" against MSHA ID from the given excel data (coalpublic2013.xls ).
Next: Write a Pandas program to import excel data (coalpublic2013.xlsx ) into a dataframe and find details where "Labor Hours" > 20000.

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

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.