pandas.DataFrame.to_markdown
बड़े int
को float
में बदल देता है। क्या यह एक बग या एक विशेषता है? क्या कोई समाधान हैं?
>>> df = pd.DataFrame({"A": [123456, 123456]})
>>> print(df.to_markdown())
| | A |
|---:|-------:|
| 0 | 123456 |
| 1 | 123456 |
>>> df = pd.DataFrame({"A": [1234567, 1234567]})
>>> print(df.to_markdown())
| | A |
|---:|------------:|
| 0 | 1.23457e+06 |
| 1 | 1.23457e+06 |
>>> print(df)
A
0 1234567
1 1234567
>>> print(df.A.dtype)
int64
1
Marc
25 पद 2020, 16:36
2 जवाब
सबसे बढ़िया उत्तर
मुझे शुरुआत में केवल एक वर्कअराउंड मिला, लेकिन स्पष्टीकरण नहीं: कॉलम को स्ट्रिंग्स में बदलना।
>>> df = pd.DataFrame({"A": [1234567, 1234567]})
>>> df["A"] = df.A.astype(str)
>>> print(df.to_markdown())
| | A |
|---:|--------:|
| 0 | 1234567 |
| 1 | 1234567 |
अद्यतन:
मुझे लगता है कि यह 2 तत्वों के कारण होता है:
tabulate
_column_type फ़ंक्शन >:
def _column_type(strings, has_invisible=True, numparse=True):
"""The least generic type all column values are convertible to.
इसे tablefmt="pretty"
के माध्यम से रूपांतरण को अक्षम करके हल किया जा सकता है:
print(df.to_markdown(tablefmt="pretty"))
+---+---------+
| | A |
+---+---------+
| 0 | 1234567 |
| 1 | 1234567 |
+---+---------+
- जब एक से अधिक कॉलम हों, और उनमें से एक में
float
नंबर हों। चूंकिसारणी
डेटा निकालने के लिएdf.values
का उपयोग करता है, जोDataFrame
कोnumpy.array
में बदल देता है, सभी मान फिर उसीdtype
(float
) में बदल दिया जाता है। इस पर इस मुद्दे में भी चर्चा की गई है।
>>> df = pd.DataFrame({"A": [1234567, 1234567], "B": [0.1, 0.2]})
>>> print(df)
A B
0 1234567 0.1
1 1234567 0.2
>>> print(df.A.dtype)
int64
>>> print(df.to_markdown(tablefmt="pretty"))
+---+-----------+-----+
| | A | B |
+---+-----------+-----+
| 0 | 1234567.0 | 0.1 |
| 1 | 1234567.0 | 0.2 |
+---+-----------+-----+
>>> df.values
array([[1.234567e+06, 1.000000e-01],
[1.234567e+06, 2.000000e-01]])
0
Marc
26 पद 2020, 00:25
यदि आप पांडा विकल्पों की जांच करते हैं, तो महत्वपूर्ण अंकों की डिफ़ॉल्ट संख्या 6 है।
import pandas as pd
pd.describe_option()
display.precision : int
Floating point output precision (number of significant digits). This is
only a suggestion
[default: 6] [currently: 6]
0
r-beginners
25 पद 2020, 17:17