@@ -1692,17 +1692,17 @@ Consider this example:
16921692 import pandas as pd
16931693 import numpy as np
16941694
1695- # Create a DataFrame with a problematic floating point value
1696- df = pd.DataFrame({' value' : [0.1 + 0.2 ]})
1697- print ( f " Original value: { df[' value' ].iloc[0 ]!r } " )
1698-
1699- # Save to CSV and read back
1700- df.to_csv( ' test_precision.csv ' , index = False )
1701- df_read = pd.read_csv (' test_precision.csv' )
1702- print ( f " After CSV roundtrip: { df_read[ ' value ' ].iloc[ 0 ] !r } " )
1703- print ( f " Values are equal: { df[ ' value ' ].iloc[ 0 ] == df_read[' value' ].iloc[0 ]} " )
1704-
1705- .. ipython :: python
1695+ # Create a DataFrame with a problematic floating point value
1696+ df = pd.DataFrame({' value' : [0.1 + 0.2 ]})
1697+ original_value = df[' value' ].iloc[0 ]
1698+ print ( f " Original value: { original_value !r } " )
1699+
1700+ # Save to CSV and read back
1701+ df.to_csv (' test_precision.csv' , index = False )
1702+ df_read = pd.read_csv( ' test_precision.csv ' )
1703+ read_value = df_read[' value' ].iloc[0 ]
1704+ print ( f " After CSV roundtrip: { read_value !r } " )
1705+ print ( f " Values are equal: { original_value == read_value } " ) .. ipython:: python
17061706 :suppress:
17071707
17081708 import os
@@ -1721,22 +1721,23 @@ roundtrip operations.
17211721
17221722.. ipython :: python
17231723
1724- # Example with high precision number
1725- df = pd.DataFrame({' precision_test' : [123456789.123456789 ]})
1726- print (f " Original: { df[' precision_test' ].iloc[0 ]} " )
1724+ # Example with high precision number
1725+ df = pd.DataFrame({' precision_test' : [123456789.123456789 ]})
1726+ original_val = df[' precision_test' ].iloc[0 ]
1727+ print (f " Original: { original_val} " )
17271728
1728- # Default behavior
1729- df.to_csv(' default.csv' , index = False )
1730- df_default = pd.read_csv(' default.csv' )
1729+ # Default behavior
1730+ df.to_csv(' default.csv' , index = False )
1731+ df_default = pd.read_csv(' default.csv' )
17311732
1732- # With explicit precision control
1733- df.to_csv(' formatted.csv' , index = False , float_format = ' %.15g ' )
1734- df_formatted = pd.read_csv(' formatted.csv' )
1733+ # With explicit precision control
1734+ df.to_csv(' formatted.csv' , index = False , float_format = ' %.15g ' )
1735+ df_formatted = pd.read_csv(' formatted.csv' )
17351736
1736- print ( f " Default read: { df_default[' precision_test' ].iloc[0 ]} " )
1737- print ( f " Formatted read: { df_formatted[' precision_test' ].iloc[0 ]} " )
1738-
1739- .. ipython :: python
1737+ default_val = df_default[' precision_test' ].iloc[0 ]
1738+ formatted_val = df_formatted[' precision_test' ].iloc[0 ]
1739+ print ( f " Default read: { default_val } " )
1740+ print ( f " Formatted read: { formatted_val } " ) .. ipython:: python
17401741 :suppress:
17411742
17421743 for f in [' default.csv' , ' formatted.csv' ]:
@@ -1769,7 +1770,7 @@ Different format specifiers have different effects on precision and output forma
17691770 df = pd.DataFrame({' number' : [123456789.123456789 ]})
17701771
17711772 formats = {' %.6f ' : ' 6 decimal places' ,
1772- ' %.10g ' : ' 10 significant digits' ,
1773+ ' %.10g ' : ' 10 significant digits' ,
17731774 ' %.6e ' : ' scientific notation' }
17741775
17751776 for fmt, description in formats.items():
0 commit comments