In [1]:
import pandas as pd
#http://www.eia.gov/coal/
In [3]:
#get directory listing
ls
Volume in drive C has no label.
Volume Serial Number is B8DF-9C15
Directory of C:\Users\Admin\documents\python\rs_explore\dev
12/15/2016 01:44 PM <DIR> .
12/15/2016 01:44 PM <DIR> ..
12/15/2016 07:33 AM <DIR> .ipynb_checkpoints
12/15/2016 01:44 PM 1,627 get_data.ipynb
1 File(s) 1,627 bytes
3 Dir(s) 3,762,188,288 bytes free
In [5]:
#what version of pandas
print(pd.__version__)
0.18.1
In [24]:
#get the first data file (use tab to auto complete from list of files)
df1 = pd.read_excel("../data/coalpublic2013.xls",header=2,index_col='MSHA ID')
#check your data frame
df1.head()
Out[24]:
Year
Mine Name
Mine State
Mine County
Mine Status
Mine Type
Company Type
Operation Type
Operating Company
Operating Company Address
Union Code
Coal Supply Region
Production (short tons)
Average Employees
Labor Hours
MSHA ID
103381
2013
Tacoa Highwall Miner
Alabama
Bibb
Active, men working, not producing
Surface
Indepedent Producer Operator
Mine only
Jesse Creek Mining, Llc
1615 Kent Dairy Rd, Alabaster, AL 35007
Appalachia Southern
56004
10
22392
103404
2013
Reid School Mine
Alabama
Blount
Permanently abandoned
Surface
Indepedent Producer Operator
Mine only
Taft Coal Sales & Associates,
3000 Riverchase Galleria Ste 1, Birmingham, AL...
UNIT
Appalachia Southern
28807
18
28447
100759
2013
North River #1 Underground Min
Alabama
Fayette
Active, men working, not producing
Underground
Indepedent Producer Operator
Mine and Preparation Plant
Jim Walter Resources Inc
3114 County Rd 63 S, Berry, AL 35546
UNIT
Appalachia Southern
1440115
183
474784
103246
2013
Bear Creek
Alabama
Franklin
Active
Surface
Indepedent Producer Operator
Mine only
Birmingham Coal & Coke Co., In
912 Edenton Street, Birmingham, AL 35242
Appalachia Southern
87587
13
29193
103451
2013
Knight Mine
Alabama
Franklin
Active
Surface
Indepedent Producer Operator
Mine only
Birmingham Coal & Coke Co., In
P.O. Box 354, Lynn, AL 35242
Appalachia Southern
147499
27
46393
In [22]:
#get the unique values for Company Type column
df1['Company Type'].unique()
Out[22]:
array(['Indepedent Producer Operator', 'Operating Subsidiary', 'Contractor'], dtype=object)
In [25]:
df1['Company Type'].replace('Indepedent Producer Operator','Independent Producer Operator', inplace=True)
In [26]:
df1.head()
Out[26]:
Year
Mine Name
Mine State
Mine County
Mine Status
Mine Type
Company Type
Operation Type
Operating Company
Operating Company Address
Union Code
Coal Supply Region
Production (short tons)
Average Employees
Labor Hours
MSHA ID
103381
2013
Tacoa Highwall Miner
Alabama
Bibb
Active, men working, not producing
Surface
Independent Producer Operator
Mine only
Jesse Creek Mining, Llc
1615 Kent Dairy Rd, Alabaster, AL 35007
Appalachia Southern
56004
10
22392
103404
2013
Reid School Mine
Alabama
Blount
Permanently abandoned
Surface
Independent Producer Operator
Mine only
Taft Coal Sales & Associates,
3000 Riverchase Galleria Ste 1, Birmingham, AL...
UNIT
Appalachia Southern
28807
18
28447
100759
2013
North River #1 Underground Min
Alabama
Fayette
Active, men working, not producing
Underground
Independent Producer Operator
Mine and Preparation Plant
Jim Walter Resources Inc
3114 County Rd 63 S, Berry, AL 35546
UNIT
Appalachia Southern
1440115
183
474784
103246
2013
Bear Creek
Alabama
Franklin
Active
Surface
Independent Producer Operator
Mine only
Birmingham Coal & Coke Co., In
912 Edenton Street, Birmingham, AL 35242
Appalachia Southern
87587
13
29193
103451
2013
Knight Mine
Alabama
Franklin
Active
Surface
Independent Producer Operator
Mine only
Birmingham Coal & Coke Co., In
P.O. Box 354, Lynn, AL 35242
Appalachia Southern
147499
27
46393
In [30]:
#replace column heading spaces with underscores
df1.rename(columns=lambda x: x.replace(" ","_"), inplace=True)
In [29]:
df1.head()
Out[29]:
Year
Mine_Name
Mine_State
Mine_County
Mine_Status
Mine_Type
Company_Type
Operation_Type
Operating_Company
Operating_Company_Address
Union_Code
Coal_Supply_Region
Production_(short_tons)
Average_Employees
Labor_Hours
MSHA ID
103381
2013
Tacoa Highwall Miner
Alabama
Bibb
Active, men working, not producing
Surface
Independent Producer Operator
Mine only
Jesse Creek Mining, Llc
1615 Kent Dairy Rd, Alabaster, AL 35007
Appalachia Southern
56004
10
22392
103404
2013
Reid School Mine
Alabama
Blount
Permanently abandoned
Surface
Independent Producer Operator
Mine only
Taft Coal Sales & Associates,
3000 Riverchase Galleria Ste 1, Birmingham, AL...
UNIT
Appalachia Southern
28807
18
28447
100759
2013
North River #1 Underground Min
Alabama
Fayette
Active, men working, not producing
Underground
Independent Producer Operator
Mine and Preparation Plant
Jim Walter Resources Inc
3114 County Rd 63 S, Berry, AL 35546
UNIT
Appalachia Southern
1440115
183
474784
103246
2013
Bear Creek
Alabama
Franklin
Active
Surface
Independent Producer Operator
Mine only
Birmingham Coal & Coke Co., In
912 Edenton Street, Birmingham, AL 35242
Appalachia Southern
87587
13
29193
103451
2013
Knight Mine
Alabama
Franklin
Active
Surface
Independent Producer Operator
Mine only
Birmingham Coal & Coke Co., In
P.O. Box 354, Lynn, AL 35242
Appalachia Southern
147499
27
46393
Content source: Ebotto1/RS-exploration
Similar notebooks: