Skip to content

Instantly share code, notes, and snippets.

@talfco
Last active March 3, 2019 14:12
Show Gist options
  • Save talfco/cf343e95d0f5bf8e56dce247ec3b80b9 to your computer and use it in GitHub Desktop.
Save talfco/cf343e95d0f5bf8e56dce247ec3b80b9 to your computer and use it in GitHub Desktop.
def create_tw_politican_table(self, apidef):
# Panda Data Frame - Table of all Parliament Members
panda_data = { 'ScreenName' : self.__col_screen_name,
'Name': self.__col_name,
'Description': self.__col_description,
"FollowersCount": self.__col_followers_count,
"FriendsCount": self.__col_friends_count,
"Party": self.__col_party
}
df = DataFrame(panda_data, index=self.__labels)
df = df.apply(self.__calculate_name_matching, axis=1)
# Sort by Followers Count
df = df.sort_values(['FollowersCount'], ascending=[0])
# Create a Plotly Table
trace = go.Table(
header=dict(values=list(df.columns)),
cells=dict(values=[df.ScreenName, df.Name, df.Description, df.FollowersCount,
df.FriendsCount, df.Party, df.col_match1, df.col_match2,
df.col_match3]))
data = [trace]
py.plot(data, filename=self.__country_code+'-tw-politician-list')
merge_df = pd.merge(left=df, right=apidef, how='left', left_on='col_match2',
right_on='col_match2')
trace = go.Table(
header=dict(values=['ScreenName', 'Name', 'FollowersCount', 'FriendsCount', 'Party',
'party', 'electedDate','gender', 'maritalStatus', 'birthDate',
'normalizedName']),
cells=dict(values=[merge_df.ScreenName, merge_df.Name, merge_df.FollowersCount,
merge_df.FriendsCount, merge_df.Party, merge_df.party,
merge_df.electedDate, merge_df.gender, merge_df.maritalStatus,
merge_df.birthDate, merge_df.col_match1_x]))
data = [trace]
py.plot(data, filename=self.__country_code+'-tw-politician-merged-list')
return merge_df
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment