Editing Community Data Science Course (Sprint 2019)/Day 7 Notes
From CommunityData
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 20: | Line 20: | ||
filehandle = open('~/Desktop/collisions.csv', 'w') | filehandle = open('~/Desktop/collisions.csv', 'w') | ||
filehandle.write(response. | filehandle.write(response.content()) | ||
filehandle.close() | filehandle.close() | ||
Line 38: | Line 38: | ||
'''Code to open a file and print the first column''' | '''Code to open a file and print the first column''' | ||
file_handle = open(' | file_handle = open('sdot_collisions_seattle.csv', 'r') # open the csv file | ||
for line in file_handle: # loop through the file one line at a time. | for line in file_handle: # loop through the file one line at a time. | ||
line_clean = line.strip() # remove the newline character at end of line | line_clean = line.strip() # remove the newline character at end of line | ||
Line 50: | Line 50: | ||
(You'll want to open this window in a wide browser) | (You'll want to open this window in a wide browser) | ||
file_handle = open(' | file_handle = open('sdot_collisions_seattle.csv', 'r') # open the csv file | ||
header = file_handle.readline() | header = file_handle.readline() | ||
output_handle = open(' | output_handle = open('sdot_collisitions_transformed.csv', 'w') # NOTE this will overwrite | ||
for line in file_handle: # loop through the file one line at a time. | for line in file_handle: # loop through the file one line at a time. | ||
line_clean = line.strip() # remove the newline character at end of line | line_clean = line.strip() # remove the newline character at end of line | ||
Line 59: | Line 59: | ||
output_handle.write(line) # write that line to the output. | output_handle.write(line) # write that line to the output. | ||
output_handle.close() # Close the output file after the loop. | output_handle.close() # Close the output file after the loop. | ||