python - format Date in pandas style render -


i have pandas dataframe 3 columns of first date. produce html output use this:

html_string = df.style.format({'second': "{:0,.0f}",third: "{:0,.0f}"}).set_table_styles(styles).render() 

how possible specifiy format of date well...something like:

html_string = df.style.format({'date': "%y.%m",'second': "{:0,.0f}",third: "{:0,.0f}"}).set_table_styles(styles).render() 

for me works:

html_string = df.style.format({'first': lambda x: "{}".format(x.strftime('%y.%m')) ,                                 'second': "{:0,.0f}",                                'third': "{:0,.0f}"}).set_table_styles('styles').render() print (html_string) 

sample:

df = pd.dataframe({ 'first':['2015-01-05','2015-01-06','2015-01-07'],                     'second':[4,2.1,5.9],                    'third':[8,5.1,7.7]}) df['first'] = pd.to_datetime(df['first'] ) print (df)        first  second  third 0 2015-01-05     4.0    8.0 1 2015-01-06     2.1    5.1 2 2015-01-07     5.9    7.7 

<table id="t_a301a12e_54ca_11e6_9a6f_acb57da49b4f" none>        <thead>        <tr>          <th class="blank">            <th class="col_heading level0 col0">first              <th class="col_heading level0 col1">second                <th class="col_heading level0 col2">third        </tr>      </thead>    <tbody>        <tr>          <th id="t_a301a12e_54ca_11e6_9a6f_acb57da49b4f" class="row_heading level2 row0">          0            <td id="t_a301a12e_54ca_11e6_9a6f_acb57da49b4frow0_col0" class="data row0 col0">            2015.01              <td id="t_a301a12e_54ca_11e6_9a6f_acb57da49b4frow0_col1" class="data row0 col1">              4                <td id="t_a301a12e_54ca_11e6_9a6f_acb57da49b4frow0_col2" class="data row0 col2">                8        </tr>        <tr>          <th id="t_a301a12e_54ca_11e6_9a6f_acb57da49b4f" class="row_heading level2 row1">          1            <td id="t_a301a12e_54ca_11e6_9a6f_acb57da49b4frow1_col0" class="data row1 col0">            2015.01              <td id="t_a301a12e_54ca_11e6_9a6f_acb57da49b4frow1_col1" class="data row1 col1">              2                <td id="t_a301a12e_54ca_11e6_9a6f_acb57da49b4frow1_col2" class="data row1 col2">                5        </tr>        <tr>          <th id="t_a301a12e_54ca_11e6_9a6f_acb57da49b4f" class="row_heading level2 row2">          2            <td id="t_a301a12e_54ca_11e6_9a6f_acb57da49b4frow2_col0" class="data row2 col0">            2015.01              <td id="t_a301a12e_54ca_11e6_9a6f_acb57da49b4frow2_col1" class="data row2 col1">              6                <td id="t_a301a12e_54ca_11e6_9a6f_acb57da49b4frow2_col2" class="data row2 col2">                8        </tr>      </tbody>  </table>


Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -