Combining Excels

This notebook will combine all of the excel files that you create in the Combining CSV's notebook. It will also add reactor labels for the data.


In [2]:
import pandas as pd
import numpy as np

Import

Import all of the reactor data you want to include in the final summary excel. It is useful to name each DataFrame you create with the reactor type it is related to.


In [3]:
df_BWR = pd.read_excel('../../Jimmy/BWR_Data/BWR_Combined_notsorted.xlsx', 'Sheet1')
df_VVER = pd.read_excel('../../Jimmy/VVER_Data/VVER_Combined_notsorted.xlsx', 'Sheet1')
df_RBMK = pd.read_excel('../../Jimmy/RBMK_Data/RBMK_Combined_notsorted.xlsx', 'Sheet1')

Create an overall data frame which each of the reactor data frames will be appended into. Make sure to append all of the DataFrames that you created while you were importing your excel files.


In [4]:
df_tot = df_BWR.append(df_VVER)
df_tot = df_tot.append(df_RBMK)

This allows you to see the data at the end of your combined DataFrame.


In [5]:
df_tot.tail()


Out[5]:
pu240/pu239 pu238/pu239 pu242/pu239 pu241/pu239
120 0.738669 0.014700 0.117027 0.227807
121 0.771872 0.016599 0.132420 0.238716
122 0.804588 0.018632 0.148873 0.249201
123 0.836140 0.020789 0.166407 0.259179
124 0.866612 0.023055 0.184891 0.268547

Create Reactor Column

To create your reactor column change the string in the append line to the reactor name.


In [18]:
reactor_list = []
#Change range here
for y in range(len(df_BWR):
    #Change string here
    reactor_list.append('BWR')
    
for y in range(len(df_VVER)):
    reactor_list.append('VVER')
    
for y in range(df_RBMK):
    reactor_list.append('RBMK')
print reactor_list


['BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'BWR', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'VVER', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK', 'RBMK']

Check to make sure that the length of the list of reactor names you just made matches the length of your DataFrame.


In [19]:
print 'list', len(reactor_list)
print 'df', len(df_tot)


list 735
df 735

Create a new column with the reactor names in it and then check to make sure it added to the DataFrame correctly.


In [20]:
df_tot['reactor'] = reactor_list

In [21]:
df_tot.tail()


Out[21]:
pu240/pu239 pu238/pu239 pu242/pu239 pu241/pu239 reactor
120 0.738669 0.014700 0.117027 0.227807 RBMK
121 0.771872 0.016599 0.132420 0.238716 RBMK
122 0.804588 0.018632 0.148873 0.249201 RBMK
123 0.836140 0.020789 0.166407 0.259179 RBMK
124 0.866612 0.023055 0.184891 0.268547 RBMK

Change the order of the columns so that the reactor column is first.


In [22]:
col = list(df_tot.columns)
col = col[-1:] + col[-2:-1] + col[:-2]
print col
df_tot = df_tot[col]


['reactor', u'pu240/pu239', u'pu238/pu239', u'pu242/pu239', u'pu241/pu239']

In [24]:
df_tot.tail()


Out[24]:
reactor pu240/pu239 pu238/pu239 pu242/pu239 pu241/pu239
120 RBMK 0.738669 0.014700 0.117027 0.227807
121 RBMK 0.771872 0.016599 0.132420 0.238716
122 RBMK 0.804588 0.018632 0.148873 0.249201
123 RBMK 0.836140 0.020789 0.166407 0.259179
124 RBMK 0.866612 0.023055 0.184891 0.268547

Use this to make sure specific groups of reactors types worked. You can look at different reactors by switching the string in the get_group(). you can look at .head() and .tail() to make sure the indexes match up.


In [25]:
grouped = df_tot.groupby('reactor')
grouped.get_group('BWR').head()


Out[25]:
reactor pu240/pu239 pu238/pu239 pu242/pu239 pu241/pu239
0 BWR 0.022653 0.000043 0.000010 0.001188
1 BWR 0.044642 0.000146 0.000083 0.004734
2 BWR 0.065284 0.000288 0.000278 0.010166
3 BWR 0.084764 0.000463 0.000634 0.016902
4 BWR 0.103365 0.000671 0.001169 0.024433

Export to excel

Export the DataFrame to an excel sheet. index = False means that the index column will not be exported.


In [26]:
df_tot.to_excel('VVER_RBMK_BWR_generated.xlsx', 'Sheet1', index = False)

In [ ]: