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 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