Pandas Excel: Import excel data into a dataframe
1. Import Excel Data
Write a Pandas program to import given excel data (coalpublic2013.xlsx ) into a Pandas dataframe. Go to Excel data
Sample Solution:
Python Code :
import pandas as pd
import numpy as np
df = pd.read_excel('E:\coalpublic2013.xlsx')
print(df.head)
Sample Output:
Year MSHA ID Mine_Name Production Labor_Hours
0 2013 103381 Tacoa Highwall Miner 56004 22392
1 2013 103404 Reid School Mine 28807 28447
2 2013 100759 North River #1 Underground Min 1440115 474784
3 2013 103246 Bear Creek 87587 29193
4 2013 103451 Knight Mine 147499 46393
5 2013 103433 Crane Central Mine 69339 47195
6 2013 100329 Concord Mine 0 144002
7 2013 100851 Oak Grove Mine 2269014 1001809
8 2013 102901 Shoal Creek Mine 0 12396
9 2013 102901 Shoal Creek Mine 1453024 1237415
10 2013 103180 Sloan Mountain Mine 327780 196963
11 2013 103182 Fishtrap 175058 87314
12 2013 103285 Narley Mine 154861 90584
13 2013 103332 Powhatan Mine 140521 61394
14 2013 103375 Johnson Mine 580 1900
15 2013 103419 Maxine-Pratt Mine 125824 107469
16 2013 103432 Skelton Creek 8252 220
17 2013 103437 Black Warrior Mine No 1 145924 70926
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
22 2013 103422 Clark No 1 Mine 122727 140250
23 2013 103467 Helena Surface Mine 59664 30539
24 2013 101247 No 4 Mine 2622528 1551141
25 2013 101401 No 7 Mine 5405412 2464719
26 2013 103172 Searles Mine No. 2, 3, 4, 5, 6 258078 119542
27 2013 103179 Fleetwood Mine No 1 75937 63745
28 2013 103303 Shannon Mine 317491 164388
29 2013 103323 Deerlick Mine 133452 46381
30 2013 103364 Brc Alabama No. 7 Llc 0 14324
31 2013 103436 Swann's Crossing 137511 77190
32 2013 100347 Choctaw Mine 537429 215295
33 2013 101362 Manchester Mine 219457 116914
34 2013 102996 Jap Creek Mine 375715 164093
35 2013 103155 Corinth Prep Plant 0 27996
36 2013 103155 Corinth Prep Plant 0 51994
37 2013 103195 Mccollum/Sparks Branch Mine 71910 17411
38 2013 103342 Reese's Branch Mine 263888 115123
39 2013 103370 Cresent Valley Mine 2860 621
40 2013 103372 Cane Creek Mine 66258 32401
41 2013 103376 Town Creek 299167 176499
42 2013 103389 Carbon Hill Mine 76241 84966
43 2013 103410 Coal Valley Mine 407841 158591
44 2013 103423 Dutton Hill Mine 37275 9162
45 2013 1519322 Ghm #25 25054 3108
46 2013 103321 Poplar Springs 189370 76366
47 2013 103358 Old Union 284563 161805
48 2013 5000030 Usibelli 1631584 286079
49 2013 201195 Kayenta Mine 7602722 1015333
Excel Data:
coalpublic2013.xlsx:
For more Practice: Solve these Related Problems:
- Write a Pandas program to import an Excel file (coalpublic2013.xlsx) into a DataFrame and display its first five rows.
- Write a Pandas program to read an Excel file and confirm that the resulting DataFrame is not empty.
- Write a Pandas program to import data from coalpublic2013.xlsx and print the head of the DataFrame using a custom index.
- Write a Pandas program to load coalpublic2013.xlsx into a DataFrame and verify the imported data type of the DataFrame.
Go to:
PREV : Python Pandas Excel Exercises Home.
NEXT : Get Data Types of Excel Data.
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.
