Python Forum
Dataframe Removes Zeros - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Dataframe Removes Zeros (/thread-29708.html)



Dataframe Removes Zeros - JoeDainton123 - Sep-16-2020

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.


RE: Dataframe Removes Zeros - bowlofred - Sep-16-2020

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



RE: Dataframe Removes Zeros - scidam - Sep-17-2020

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.