Precision lost while using read_csv in pandas

后端 未结 1 1217
你的背包
你的背包 2020-12-06 05:35

I have files of the below format in a text file which I am trying to read into a pandas dataframe.

895|2015-4-23|19|10000|LA|0.4677978806|0.4773469340|0.4089         


        
相关标签:
1条回答
  • 2020-12-06 05:57

    It is only display problem, see docs:

    #temporaly set display precision
    with pd.option_context('display.precision', 10):
        print df
    
         0          1   2      3   4             5            6             7   \
    0  895  2015-4-23  19  10000  LA  0.4677978806  0.477346934  0.4089938425   
    
                 8             9            10            11  12  
    0  0.8224291972  0.8652525793  0.682994286  0.5139162227 NaN    
    

    EDIT: (Thank you Mark Dickinson):

    Pandas uses a dedicated decimal-to-binary converter that sacrifices perfect accuracy for the sake of speed. Passing float_precision='round_trip' to read_csv fixes this. See the documentation for more.

    0 讨论(0)
提交回复
热议问题