Skip to content

Instantly share code, notes, and snippets.

@UweZiegenhagen
Created May 9, 2021 08:39
Show Gist options
  • Select an option

  • Save UweZiegenhagen/bb73f422cc57fea88b29186bc945c7a3 to your computer and use it in GitHub Desktop.

Select an option

Save UweZiegenhagen/bb73f422cc57fea88b29186bc945c7a3 to your computer and use it in GitHub Desktop.
Medium-20210509-4.py
# names of the comparison column
check_colnames= [s + '_c' for s in columnnames1]
# initialize an empty dataframe for the log
logdf=pd.DataFrame(index=[True,False])
for column in check_colnames:
t=comparison[column].value_counts() # returns a series
tt=pd.DataFrame(t) # makes a DF out of the series
logdf = logdf.join(tt,how='outer') # join the two dfs
# transpose for better readability
logdf = logdf.transpose()
# Ensure fixed sequence of the columns
logdf=logdf.reindex(sorted(logdf.columns),axis=1)
# write to disk
logdf.to_excel('logfile.xlsx')
# for better viewing on the screen
logdf.fillna('-',inplace=True)
pd.options.display.float_format = '{:,.0f}'.format
print(logdf)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment