Open
Conversation
This homework python program takes the homework.csv file and applies transformations to it to create a formatted.csv file. Two python standard library modules of csv and decimal were used. The main function runs first and calls other functions to apply the needed transformations. This program was designed with the ability to quickly modify and include more transformations such as other dimensions, weight conversions, or others not included in homework.csv. The beginning of the main function opens the homework.csv file and reads the data using the csv library. Empty lists and a variable are then defined to be used throughout the rest of the function. Next, the for-loop goes through each row that has been read so that select information can be modified. The header row has a unique function of deciding which columns will need edited, so it is picked out by an if statement. Header titles are checked, by calling other functions, to append those with a date, currency, distance/dimension, or UPC to transformation lists. Titles’ column number starting from zero are kept track of and appended to the lists for reference in the data rows. When in the else statement which involves the data rows, column count is kept track of again and used to check against the transformation lists to transform the corresponding data items. Transformed data is lastly added to a list and written to the formatted.csv file. The first function of “isData” is called from the header-if statement in the main function and takes a header title. It simply returns true if “date” is in the header title. Similarly, “isCurrency” , “isDistance”, and “isUPC” check for their corresponding key words that were selected by manually scanning/searching through the homework.csv file. All other functions serve their corresponding transformation by taking the data item in and applying the conversion or formatting requested. The “makeISO” function puts dates into ISO format by splitting the date given and formatting it. Another function, “roundCurrency”, caused some issues in testing with the inconsistent use of dollar signs and commas so those are filtered out to just format the number with two decimal places. Since cubic feet is the only unit of measure used needing conversion to inches, “convertInches3” simply handles this conversion and formatting. Lastly, “convertString” is used exclusively for UPC to be handled as a string.
golder_elt_homework
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
GolderHomeworkDescription.pdf