Dec-28-2020, 10:13 PM
This works:
Did I have to do something else to print out the Styler object (which did seem to be there when I typed merged_df.style and/or merged_df.style.format)?
I'm using Python 3.7.9.
format_mapping = {markets[0]+'_Close':'{:.2f}',markets[1]+'_Close':'{:.1f}',markets[2]+'_Close':'{:.2f}', markets[3]+'_Close':'{:.4f}', markets[4]+'_Close':'{:.4f}'} for key, value in format_mapping.items(): merged_df[key] = merged_df[key].apply(value.format)I did a lot of reading about df.style.format . I don't understand why this did not work:
format_dict = {markets[0]+'_Close':'{:.2f}',markets[1]+'_Close':'{:.1f}',markets[2]+'_Close':'{:.2f}', markets[3]+'_Close':'{:.4f}', markets[4]+'_Close':'{:.4f}'} merged_df.style.format(format_dict) #WHY DID THIS NOT WORK?I didn't get a Traceback. I just didn't see any formatting occur. Does it have to do with printing a df rather than a table?
Did I have to do something else to print out the Styler object (which did seem to be there when I typed merged_df.style and/or merged_df.style.format)?
I'm using Python 3.7.9.