Python Forum
How to keep leading zeros with pandas?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to keep leading zeros with pandas?
#1
I have a csv file with 4 columns.
col 1 (numbers)
col 2 (text)
col 3 (numbers)
col 4 (text)

technically all four columns have a format type of general, basically my number are not really numbers which is fine.

When I import into pandas it removes my leading zeros for ONLY 3 (col 1 loads fine for some reason). How can I keep the leading zeros for col 3? I guess I have to tell pandas to treat those columns as strings?
df = pd.read_csv("myfile.csv")
*I am new to python
Reply


Messages In This Thread
How to keep leading zeros with pandas? - by eeps24 - May-20-2020, 04:06 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Removing leading whitespaces palladium 1 749 Mar-24-2023, 04:15 PM
Last Post: bowlofred
  Removing leading\trailing spaces azizrasul 8 2,842 Oct-23-2022, 11:06 PM
Last Post: azizrasul
  How to retrieve records in a DataFrame (Python/Pandas) that contains leading or trail mmunozjr 3 1,826 Sep-05-2022, 11:56 AM
Last Post: Pedroski55
  -i option changes sys.path (removes leading empty string '') markanth 6 2,072 Aug-26-2022, 09:27 PM
Last Post: markanth
  remove zeros at the end of a number Frankduc 7 2,229 Feb-25-2022, 03:48 PM
Last Post: Frankduc
  Solving for zeros of an equation! fmitchell17 0 1,872 Apr-05-2021, 07:49 PM
Last Post: fmitchell17
  Dataframe Removes Zeros JoeDainton123 2 4,471 Sep-17-2020, 12:47 PM
Last Post: scidam
  Cancelling 'open directory' leading to crash Fairbz_ 1 2,220 May-08-2020, 03:14 PM
Last Post: DPaul
  leading zero number formatting RedSkeleton007 3 3,992 Jan-27-2019, 04:56 PM
Last Post: RedSkeleton007
  Probs with leading zeros falling away :-) Badosc 2 2,910 Dec-04-2018, 08:57 PM
Last Post: Badosc

Forum Jump:

User Panel Messages

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