title: Formatting options for pandas.Timedelta?
body: <p>Consider this snippet</p>
  <pre><code>In[1]: import pandas as pd
  In[2]: str(pd.to_timedelta(&quot;1354s&quot;))
  Out[2]: '0 days 00:22:34'
  </code></pre>
  <p>I would prefer the format
  <code>'22:34'</code> instead, since there is 0 hours and 0 days.</p>
  <p>How can I demand such a 'most compact representation' ?</p>
  <hr />
  <p>EDIT: More examples.</p>
  <pre><code>In[3]: [ str(pd.to_timedelta(t,unit='s')) for t in [10,1000,10000]]
  Out[3]: ['0 days 00:00:10', '0 days 00:16:40', '0 days 02:46:40']
  </code></pre>
  <p>But I would like to get
  <code>['10', '16:40', '2:46:40']</code>
  or maybe
  <code>['10s', '16m 40s', '2h 46m 40s']</code>
  or something along those lines</p>
  <hr />
  <p>EDIT:</p>
  <p>The linked dupe suggest that one should - at least in the case of python standard timedeltas - create a custom formatter. I decided to go like this:</p>
  <pre><code>
  def pd_td_fmt(td):
      import pandas as pd
      assert isinstance(td, pd.Timedelta)
      abbr = {'days': 'd', 'hours': 'h', 'minutes': 'min', 'seconds': 's', 'milliseconds': 'ms', 'microseconds': 'us',
          'nanoseconds': 'ns'}
      return &quot;&quot;.join(f&quot;{v}{abbr[k]}&quot; for k, v in td.components._asdict().items() if v != 0)
  </code></pre>
  <p>With output example:</p>
  <pre><code>[ pd_td_fmt(pd.to_timedelta(t,unit='s')) for t in [10,1000,10000]]
  Out[9]: ['10s', '16min40s', '2h46min40s']
  </code></pre>