Home > database >  Importing file in pandas with read_table() cuts decimal places
Importing file in pandas with read_table() cuts decimal places

Time:11-22

I have a txt file like this (separated by tab):

Variance Mean
0.001435955236 -0.001117
0.002473570225 0.003123
0.002334629124 -0.003471

...and so on.

I load it using pandas.read_table() and the result is a dataframe like this:

Variance Mean
0 0.001436 -0.001117
1 0.002474 0.003123
2 0.002335 -0.003471

Why it cuts the decimal places in Variance column? I need those values to be like in the original file.

The file can be found here: https://github.com/jarsonX/Temp_files

My code:

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd

df_assets = pd.read_table('assets.txt')

df_assets.head(10)

CodePudding user response:

Pandas does not actually "cut" the decimal place, it just rounds when printing. To print with display precision, use

with pd.option_context('display.precision', 10):
    print(df_assets)
  • Related