Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Dataframe Removes Zeros
#1
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.
Reply
#2
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
Reply
#3
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  -i option changes sys.path (removes leading empty string '') markanth 6 1,897 Aug-26-2022, 09:27 PM
Last Post: markanth
  remove zeros at the end of a number Frankduc 7 2,102 Feb-25-2022, 03:48 PM
Last Post: Frankduc
  The code I have written removes the desired number of rows, but wrong rows Jdesi1983 0 1,599 Dec-08-2021, 04:42 AM
Last Post: Jdesi1983
  Solving for zeros of an equation! fmitchell17 0 1,803 Apr-05-2021, 07:49 PM
Last Post: fmitchell17
  How to keep leading zeros with pandas? eeps24 1 6,469 May-20-2020, 07:51 PM
Last Post: deanhystad
  Why does pop() removes an element from more than one list? albufork 5 2,771 Nov-17-2019, 08:01 AM
Last Post: buran
  Probs with leading zeros falling away :-) Badosc 2 2,826 Dec-04-2018, 08:57 PM
Last Post: Badosc
  Controlling trailing zeros with rounding? RedSkeleton007 1 24,408 Jan-25-2018, 07:23 AM
Last Post: j.crater
  leading zeros kerzol81 7 6,988 Apr-23-2017, 03:53 PM
Last Post: kerzol81
  program is related to leading zeros amrita 3 3,775 Apr-13-2017, 06:57 AM
Last Post: wavic

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020