w3resource

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


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:


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.