Git Product home page Git Product logo

Comments (1)

MoritzMaxeiner avatar MoritzMaxeiner commented on August 15, 2024

Hey @astanin, I appreciate the package, but just wanted to let you know that pandas DataFrames np.int64 numbers are still evaluated as float when there are other float columns. This is because this call to values causes numpy to upcast all integer columns to float columns. Ideally instead of just using the values, each cell would be considered individually.

I'm using a quick and dirty hack to get around this by reapplying the appropriate dtype to each cell afterwards here:

rows = [list([tabular_data.dtypes[tabular_data.keys()[i]].type(cell) for i, cell in enumerate(row)]) for row in vals]

This is probably unsafe in ways I don't know, but it does allow me to print the issue's primary example correctly (without this hack it still prints the output the original reported posted):

from tabulate import tabulate
import pandas as pd
df = pd.DataFrame({'A':[1,2,3,4],'B':[.20942, .092384, .019823, .01923]})
print(tabulate(df, floatfmt='.2f', headers=df.columns, tablefmt='pipe'))
|    |   A |    B |
|---:|----:|-----:|
|  0 |   1 | 0.21 |
|  1 |   2 | 0.09 |
|  2 |   3 | 0.02 |
|  3 |   4 | 0.02 |

from python-tabulate.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.