0

I have a dataframe which I want to use to create a table. The dataframe contains data in float form which I have already rounded to two decimal places. Here is a dataframe which is a subset of the dataframe I am working on:

    Band        R^2
0   Band2 Train 0.37
1   Band3 Train 0.50
2   Band4 Train 0.19
3   Band2 Test  0.41
4   Band3 Test  0.53
5   Band4 Test  0.12

As you can see all data in the R^2 column are rounded. I have written the following simple code to create a table which I intend to export as a png so I can embed it in a LaTeX document. Here is the code:

ax1 = plt.subplot(111,frameon = False)
ax1.xaxis.set_visible(False)
ax1.yaxis.set_visible(False)
ax1.set_frame_on(False)
myTable = table(ax1, df)
myTable.auto_set_font_size(False)
myTable.set_fontsize(13)
myTable.scale(1.2, 3.5)

Here is the table:

Table

Can anybody explain why the data in the R^2 are longer than two decimal places?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Tom
  • 11
  • 4
  • Hi everyone,Sorry but I made a mess of displaying the dataframe. The dataframe should contain a column named 'R^2' which contains the following values:0.37, 0.50, 0.19,0.41,0.53,0.12. However, they are all appearing as values with 16 decimal places – Tom Mar 12 '18 at 18:27
  • Floating point numbers are not stored in programming languages in base-10 decimal format. See [Is floating point math broken?](https://stackoverflow.com/questions/588004/is-floating-point-math-broken) – jpp Mar 13 '18 at 17:16
  • Thanks JPP. I'll read up on that. In the meantime I've discovered how to simply export the LaTeX code to create the required table directly from the dataframe [here](https://stackoverflow.com/questions/14380371/export-a-latex-table-from-pandas-dataframe) – Tom Mar 14 '18 at 15:59

0 Answers0