w3resource

Pandas Excel: Find a specific MSHA ID

Pandas: Excel Exercise-10 with Solution

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:


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

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.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Share this Tutorial / Exercise on : Facebook and Twitter

Python: Tips of the Day

Split a String:

>>> sentence = 'this is, a python, tutorial, about, idioms.'
>>> sentence.split(', ')
['this is', 'a python', 'tutorial', 'about', 'idioms.']
>>> sentence.split(', ', 2)
['this is', 'a python', 'tutorial, about, idioms.']
>>> sentence.rsplit(', ')
['this is', 'a python', 'tutorial', 'about', 'idioms.']
>>> sentence.rsplit(', ', 2)
['this is, a python, tutorial', 'about', 'idioms.']