Python Forum

Full Version: Dataframe Removes Zeros
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello all;

I am importing an excel sheet into python as a dataframe using the code:-

Report = pandas.read_excel(Crack_Report, sheet_name="Current", usecols=("A:BA"), skiprows=(4))
In this excel sheet i have a set of columns with the following values:-
Column (A) Column (B)
043.0550 043.0550
049.1100 049.1100

However after importing the data, python shows these values in the dataframe as:-
43.055 43.055
49.11 49.11

It strips away the leading 0 which is fine but it also removes all of the zeros after the decimal point.

Can anyone tell me how i can overcome this?

Thank you.
Are these really numbers with a custom display format, or should they just be considered strings of digits?

If they're really numbers, is it the case that Excel has a specific format selected (like "###.####")? You could replicate that with:

l = [43.055, 49.11]
for number in l:
    print(f"{number:08.4f}")
Output:
043.0550 049.1100
read_excel automatically converts to floats/integers, if look content that similar to floats/integers;
You can try to turn off such conversion by passing dtype=np.object argument to the read_excel function.