title: Shorten decimal numbers of Pandas dataframe as with Python's decimal modules
body: <p>I have several dataframe that looks like this.</p>
  <pre><code>data = {'col1': [3.1415926535, 28, -0.0000000000000000618, 1.100000001],
          'col2': ['string1', 'string2', 'string3', 'string4'],
          'col3': [9876543210, 0, 333.3333333, np.nan],
          'col4': [np.nan] * 4}
  df = pd.DataFrame(data, index=[1001, 1002, 1003, 1004])
  
  print(df)
                col1      col2          col3  col4
  1001  3.141593e+00   string1  9.876543e+09   NaN
  1002  2.800000e+01   string2  0.000000e+00   NaN
  1003  -6.180000e-17  string3  3.333333e+02   NaN
  1004  1.100000e+00   string4           NaN   NaN
  </code></pre>
  <p>They all have thousands of rows and hundreds of columns and are stored in CSV format.
  For reasons of storage economy, I want to optimize the precision of each value contained in the dataframes before saving them in csv.</p>
  <p>For a precision of <strong>4 digits</strong>, this could give the following results.</p>
  <pre><code>           col1     col2       col3  col4
  1001  3.141e+00  string1  9.876e+09   NaN
  1002    2.8e+01  string2      0e+00   NaN
  1003  -6.18e-17  string3  3.333e+02   NaN
  1004    1.1e+00  string4        NaN   NaN
  </code></pre>
  <p>Having a sometimes large range in the same column, the &quot;round&quot; method is not adapted to my case, because it would not allow me to maintain a similar precision between large and small values. I have also tested the &quot;float_format&quot; argument with the &quot;df.to_csv()&quot; command, but it also does not meet my need.</p>
  <p><a href="https://docs.python.org/3.7/library/decimal.html" rel="nofollow noreferrer">Python's Decimal library</a> meets this need, but I have failed to apply it on a dataframe.
  Do you have a solution to effectively apply such treatment?</p>
  <p><strong>NB:</strong> If the expected value is &quot;1.1e+00&quot; I can also accept the &quot;1.1&quot; format which will be more economical once stored in CSV. But this format may not be desirable for numbers that are too extreme or too close to zero... Scientific notation therefore seems more appropriate to me.</p>