Combining CSV's For Analysis

This notebook combines all of the compiled csv files you created from running Convert_to_csv_batch.py for a batch of reactor .out files. It combines all of the files and saves them into an excel file. There is another notebook that follows this one which will combine all of excel files you create if you are working with more than one reactor type.


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

Read CSV's in here:

Update the paths of the read_csv() to match the paths of where your csv's are stored.


In [2]:
df30 = pd.read_csv('3.0/compiled_export.csv')
df35 = pd.read_csv('3.5/compiled_export.csv')
df40 = pd.read_csv('4.0/compiled_export.csv')
df45 = pd.read_csv('4.5/compiled_export.csv')
df50 = pd.read_csv('5.0/compiled_export.csv')
df55 = pd.read_csv('5.5/compiled_export.csv')

Manual input

  • num_files: enter the number of out files there were per enrichment
  • df_list: enter a list of the dataframe names (do not put them in as strings, this is a list of objects)
  • enrichment_list: enter a list of the enrichments that you used

In [3]:
num_files = 60
df_list = [df30, df35, df40, df45, df50, df55]
enrichment_list = [3.0, 3.5, 4.0, 4.5, 5.0, 5.5]

Enter the ratios you used into the columns list.


In [4]:
columns = ['pu240/pu239', 'pu238/pu239', 'pu242/pu239', 'pu241/pu239']
def column_gen():
    for item in columns:
        yield item

Update Ranges

This loops through each of your csv files, breaks up the data into ratio columns (ie. 'pu240/pu239'), and then combines them all into a total dataframe that you can then save to a csv.


In [7]:
#looping through process

for num in range(len(df_list)):
    
    temp_list = []
    new_col = column_gen()
    
    #converts all the values in the df to float
    #removes all strings and add all values to list
    for item in list(df_list[num]['pu240/pu239']):
        try:
            float(item)
            temp_list.append(item)
        except:
            continue
            
    #the index of the temp dadtaframe is the amount of out files 
    #for each enrichment.
    temp_index = range(num_files)

    
    df_temp = pd.DataFrame(index = temp_index, columns = columns)
    
    #breaking up the data into columns of ratios.
    df_temp[next(new_col)] = temp_list[0:num_files]
    df_temp[next(new_col)] = temp_list[num_files:(num_files*2)]
    df_temp[next(new_col)] = temp_list[(num_files*2):(num_files*3)]
    df_temp[next(new_col)] = temp_list[(num_files*3):(num_files*4)]
    
    #create a column for the enrichment
    enrich = enrichment_list[num]
    df_temp['enrichment'] = [enrich]*num_files
    
    try:
        df_tot
    except:
        df_tot = df_temp
    else:
        #append to the total dataframe
        df_tot = df_tot.append(df_temp)
A check to make sure the stats on the dataframe make sense (especially length)

In [11]:
df_tot.describe()


Out[11]:
enrichment
count 360.000000
mean 4.250000
std 0.855101
min 3.000000
25% 3.500000
50% 4.250000
75% 5.000000
max 5.500000

8 rows × 1 columns

Sorting

If you want to sort your columns the following commented lines will allow you to do this.


In [ ]:
#df_sorted = df_tot.sort(columns, ascending = False)

In [ ]:
#df_sorted.to_excel('BWR_Combined_sorted.xlsx', 'Sheet1', index = False)

Save the file

Make sure that the df name is correct (currently df_tot).


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

In [ ]: