+------------+-------------+-----------------------+------------------+-------------------+---------------+------------------------------+--------+
| Technology | All Backlog | All Backlog Completed | Percent Complete | Backlog Remaining | Internal ONLY | Ext/Int & Ready For External | Non-IC |
+------------+-------------+-----------------------+------------------+-------------------+---------------+------------------------------+--------+
| Tech 1 | 2395 | 1069 | 44.63% | 1326 | 34 | 219 | 822 |
+------------+-------------+-----------------------+------------------+-------------------+---------------+------------------------------+--------+
Assuming this table is a DataFrame ... (index dropped)
The 4 right columns are INT. I am looking to have them also show % completed like I have in the other columns that were formatted to show the %. Such as ...
+------------+-------------+-----------------------+------------------+-------------------+---------------+------------------------------+--------------+
| Technology | All Backlog | All Backlog Completed | Percent Complete | Backlog Remaining | Internal ONLY | Ext/Int & Ready For External | Non-IC |
+------------+-------------+-----------------------+------------------+-------------------+---------------+------------------------------+--------------+
| Tech 1 | 2395 | 1069 | 44.63% | 1326 | 34 (3.18%) | 219 (20.48%) | 822 (76.89%) |
+------------+-------------+-----------------------+------------------+-------------------+---------------+------------------------------+--------------+
I've looked at map, applymap, and others ... but the only thing close I could get was:
+------------+-------------+-----------------------+------------------+-------------------+--------------------------------------+-----------------------------------------+----------------------------------------+
| Technology | All Backlog | All Backlog Completed | Percent Complete | Backlog Remaining | Internal ONLY | Ext/Int & Ready For External | Non-IC |
+------------+-------------+-----------------------+------------------+-------------------+--------------------------------------+-----------------------------------------+----------------------------------------+
| Tech 1 | 2395 | 1069 | 44.63% | 1326 | 34 (0 3.18% 1 3.18% dtype: float64%) | 219 (0 20.49% 1 20.49% dtype: float64%) | 822(0 76.89% 1 76.89% dtype: float64%) |
+------------+-------------+-----------------------+------------------+-------------------+--------------------------------------+-----------------------------------------+----------------------------------------+
I recognize that it is showing weird because it is trying to append a Series to the cell instead of the respective data... Hence why I am looking to map, but nothing I've found seems to match the need.
Here's the code I am currently working with.
def get_IC_percomp(df:pd.DataFrame):
"""
This function takes in the DF of the default view's data.
Takes the last 3 columns and divides by items completed.
(Checking for 0 to avoid math issues.) --- might not be possible since comparing DF columns
Columns to perform this on:
Internal ONLY
Ext/Int & Ready For External
Non-IC
Returns a dictionary like: {'Column Name': data_value, ...}
"""
logger.debug('Starting get_IC_percomp()...')
column_list = ['Internal ONLY', 'Ext/Int & Ready For External', 'Non-IC']
new_dict = {column: None for column in column_list} # could also do: dict.fromkeys(keys, None)
for col in column_list:
#if float(df['All Backlog Completed'].applymap(float)) == 0.0:
# new_dict[col] = 0
#else:
# new_dict[col] = df[col] / df['All Backlog Completed']
new_dict[col] = df[col] / df['All Backlog Completed'] * 100
logger.debug('Ending get_IC_percomp()...')
return new_dict
def chg_font_fmt(data_dict:dict):
"""
This function takes in a dictionary of data and returns
a dictionary for use in formatting the DataFrame.
"""
new_dict = dict()
new_dict['Percent Complete'] = '{:.2f}%'
new_dict['Total Percent Complete'] = '{:.2f}%'
new_dict['Historical Percent Complete'] = '{:.2f}%'
new_dict['Sustain Percent Complete'] = '{:.2f}%'
if data_dict is not None:
new_dict['Internal ONLY'] = '{:}' + ' ({}%)'.format(data_dict['Internal ONLY'])
new_dict['Ext/Int & Ready For External'] = '{:}' + ' ({}%)'.format(data_dict['Ext/Int & Ready For External'])
new_dict['Non-IC'] = '{:}' + '({}%)'.format(data_dict['Non-IC'])
return new_dict
percent_dict = None
if view_str.lower() == 'default': # default view
percent_dict = get_IC_percomp(df)
df.format(chg_font_fmt(percent_dict)).set_properties(**{'text-align': 'center'}).render()
May have found an answer here: stackoverflow.com/a/54026256/10474024 But testing has not been fruitful.