Implement simpler file merging function

finchie
Sep 7, 2023, 8:35 AM
FCHAPZLDDTY46FYACRWZOPVXYLCSUBPZVNYYGRIUO3IFC6BM2TZAC

Dependencies

  • [2] 7ZN6HHL2 Extract relevant census data

Change contents

  • replacement in project.py at line 1
    [2.35][2.36:196]()
    DATA_A = "2021Census_T24A_AUST_LGA.csv"
    DATA_B = "2021Census_T24B_AUST_LGA.csv"
    DATA_C = "2021Census_T24C_AUST_LGA.csv"
    DATA_D = "2021Census_T24D_AUST_LGA.csv"
    [2.35]
    [2.196]
    DATA_A = "2021Census_T24A_AUST_STE.csv"
    DATA_B = "2021Census_T24B_AUST_STE.csv"
    # Merge files into list of unique cells
    def merge_file_parts(filenames):
    merged_file = []
    for file_index in range(len(filenames)):
    file = open(filenames[file_index], "r").readlines()
    # Split the row into columns
    for row in range(len(file)):
    cols_in_row = file[row].split(",")
    # Remove any newlines from cells
    for column in range(len(cols_in_row)):
    cols_in_row[column] = cols_in_row[column].strip()
    file[row] = cols_in_row
    # The FIRST file in the list (DATA_A)
    if file_index == 0:
    # `merged_file` is empty, this is the first file we are processing
    merged_file = file
    else:
    for row in range(len(file)):
    # Extend with everything in row except state codes
    merged_file[row].extend(file[row][1:])
    return merged_file
  • edit in project.py at line 32
    [2.198][2.198:251]()
    # First step: clean & merge data from multiple files
  • replacement in project.py at line 248
    [2.7966][2.7966:7984]()
    print(categories)
    [2.7966]
    [2.7984]
    # print(categories)
    parts = merge_file_parts([DATA_A, DATA_B])
    print(parts[-2])