Skip to content

Instantly share code, notes, and snippets.

@tdpearson
Created December 4, 2016 06:09
Show Gist options
  • Select an option

  • Save tdpearson/3ec1ea7d7bfd6f8c59ed8895dfddc644 to your computer and use it in GitHub Desktop.

Select an option

Save tdpearson/3ec1ea7d7bfd6f8c59ed8895dfddc644 to your computer and use it in GitHub Desktop.
import pandas as pd
df = pd.DataFrame.from_csv(r"append_test.txt", sep='\t')
frames = []
for meeting in range(len(df.T)): # iterate over recorded attendances
attendees = df[df.T.iloc[meeting] == 1].index # get attendees for specific meeting
frames.append(pd.DataFrame(index=attendees, columns=attendees).fillna(1)) # create frame from attendees
# sum up jointly attended meetings
pd.concat(frames).fillna(0).groupby(level=0).sum().to_csv(r"jointly_attended.txt", sep='\t')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment