Skip to content

Instantly share code, notes, and snippets.

@rrosasl
Created November 25, 2020 17:10
Show Gist options
  • Save rrosasl/1ed7943cdc3f69ec3fa4ec74ae0d9184 to your computer and use it in GitHub Desktop.
Save rrosasl/1ed7943cdc3f69ec3fa4ec74ae0d9184 to your computer and use it in GitHub Desktop.
Cleaning spreadsheet data
# Convert Rows into DataFrame and clean data
new_header = df.iloc[0] #grab the first row for the header
df = df[1:] #take the data less the header row
df.columns = new_header #set the header row as the df header
df = df.iloc[:,1:] # Remove time stamp
# Convert to a DataFrame and render.
df = pd.DataFrame.from_records(rows)
new_header = df.iloc[0] #grab the first row for the header
df = df[1:] #take the data less the header row
df.columns = new_header #set the header row as the df header
df = df.iloc[:,1:] # Remove time stamp
#Convert votes to int
for col in df.columns:
df[col] = pd.to_numeric(df[col])
#Change column names to candidate
votes = []
for col in df.columns:
name = col[37:-1]
votes.append(name)
df.columns = votes
df = df.reset_index().iloc[:,1:]
@capncrockett
Copy link

Hey hey, thanks for the quick response. Yes I was following that medium tutorial. I did get it to work though. I think by following the previous step a little more closely? Honestly not sure.

I did wind up switching a few things to work for me. If you can spot any differences I'd be keen to know if what I did differs from what you intended or what was on that medium tutorial. https://colab.research.google.com/drive/1FIcdoo8ELCzPeltEIKixWNPIdYQZPXrl?usp=sharing

Nice job by the way! This worked really well once I got it. I'm keen to try some alternative methods of input for G Forms. Like a drag and drop reorder approach might work better for voters, be more intuitive, and you can leave some off if you'd prefer. Would this code be able to handle varied index lengths? Using the
name = col[34:-1] # Can adjust the length of the column input approach would work I think. Maybe this isn't the place for that particular convo though.

@rrosasl
Copy link
Author

rrosasl commented Aug 30, 2021 via email

@capncrockett
Copy link

Hey thanks!

I was not using it for anything specifically. I've just been a fan of it since I saw Krist Novoselic speak about it 15 some odd years ago. I've always wanted to see it take hold across the country. But, for now, I'm learning about programming and data and wanted to mess around with the back end side of things of a RCV system.

I'll check out g-forms for more. Maybe it would make sense to write an API for something like that. I'm just getting started so any projects that would look good my GitHub seem like time well spent. I appreciate your willingness to help! You will probably hear from me again :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment