I have a table of numerical in a text file with 16-digit decimal precision that I am reading into a Jupyter Notebook and converting it into a Pandas DataFrame. How can I use the decimal module with pandas to preserve the precision from the text file? Or is there anything else that would work better? Currently, it is showing only up to 5-6 decimal places. Thanks!
code:
from pathlib import Path
folder = Path("C:/This/is/the/path")
file = folder1/"thisfile.txt"
df = loadtxt(file1)
df = pd.DataFrame(df)
The input is a text file:
2 2 -14914.622755795561
3 2 -10563.365160496842
4 2 -6927.2062998872152
5 2 -3886.5429891705344
6 2 -1370.9348975732908
The output looks like this in pandas:
0 2.0 2.0 -14914.622756
1 3.0 2.0 -10563.365160
2 4.0 2.0 -6927.206300
3 5.0 2.0 -3886.542989
4 6.0 2.0 -1370.934898
with pd.option_context('display.float_format', '{:0.17f}'.format): print(df)
– ilja Jul 3 '19 at 15:26