Dec-28-2020, 02:50 PM
Here's some code:
markets = {'ES':2, 'GC':1, 'CL':2, 'EC':4, 'US':4} merge_list = [] pd.options.display.float_format = '{:.2f}'.format for market in markets: columnname_0 = market+'_Close' columnname_1 = market+'_Daily_Rtn' columnname_2 = market+'_Cum_Rtn' columnname_3 = market+'_Value' df_name = market market = pd.read_csv(r'C:\Users\drkle\{}(daily).csv'.format(market), parse_dates=["Date"], index_col="Date") merge_list.append(market_cut) merged_df = pd.concat(merge_list, axis=1)I've since realized I don't want two decimal places for all columns. I changed Line 1 from a list to dictionary with values equal to the desired number of decimal places (in column 0 for each component dataframe). I found this line on SO:
market_cut[df_name] = market_cut[df_name].map('{:,.2f}'.format)How might I build that out to call the values of markets to format accordingly (e.g. 'ES_Close' column to two decimal places, 'GC_Close' column to one decimal place, 'EC_Close' to four decimal places, etc.)? Alternatively, can you think of another way to do this? Thanks!