0

I exported string of numbers from python into a csv file:

When I open it in notepad, the data looks as such which is the real data:

enter image description here

However if I open it in excel sheet, the data looks as such which is false:

enter image description here

Can somebody please let me know how do I get to see following string of letters in the csv file:

Cell A1: 15

Cell A2: 15.0

Cell A3: 15.00

Cell A4: 15.000

Ranjan Pal
  • 307
  • 3
  • 13

2 Answers2

1

That is not actually done by csv file, but you are opening it in excel. So, Excel is just ignoring .000s and yeah! If you read that file using other program or python also then you will get .0 for sure.

You can look this article for, how to change that feature. If you are having hard time while saving csv file then, you may look here

imxitiz
  • 3,920
  • 3
  • 9
  • 33
  • Hi @Xitiz..You are right..Python can read it back the original data. However, is there any way out that I can see the original data in excel file also ? – Ranjan Pal Jul 24 '21 at 16:40
  • You may look at that article. – imxitiz Jul 24 '21 at 16:41
  • Not exactly...The changes made, gets applied for all the cells. For example if I save upto 1 decimal place, then 15 becomes 15.0 and 15.00 becomes 15.0 Also, even if I save the changes for existing file, the next time I open the csv as excel, the saved changes disappear. – Ranjan Pal Jul 24 '21 at 17:00
  • Have you save, that file? I think you forget to save that file. Just try one more time. – imxitiz Jul 24 '21 at 17:01
  • Yes...I saved it using same file name as well as different file name. While saving, it gives a pop-up message that save changes will be lost. That's why the custom edits are lost. – Ranjan Pal Jul 24 '21 at 17:04
  • 1
    I think, now you need [this](https://community.spiceworks.com/topic/270336-saving-as-csv-and-keeping-leading-zeros) – imxitiz Jul 24 '21 at 17:10
  • 1
    @RanjanPal If you like my effort you may upvote my answer! – imxitiz Jul 26 '21 at 14:14
0

Since the 1st step is related to exporting the data from python into csv, all leading and trailing zeroes can be truncated at this stage itself.

One such reference that can be used is shown here: Removing Trailing Zeros in Python

Ranjan Pal
  • 307
  • 3
  • 13