473,398 Members | 2,427 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

pyExcelerator big integer values

I use pyExcelerator to import some data from xml file. One column
contains integer values like:
4750456000708
4750456000715
4750456000333
....
But when I do import the pyExcelerator converts them to something like
this:
4.7504560002e+12
4.7504560007e+12
4.7504560007e+12
4.7504560003e+12

How I understand it's because the integer value is too big. If the type
of the items was string, then all would be fine, but I can't control
the file content.

The question is, how can I import the integers in normal format.

Jan 9 '07 #1
4 2070
On Jan 10, 12:30 am, "Gacha" <gatis.toms...@gmail.comwrote:
I use pyExcelerator to import some data from xml file. One column
contains integer values like:
4750456000708
4750456000715
4750456000333
I think you must mean "xls", not "xml".

Those are integers only in the mathematical sense. The value of each
number cell in an XLS file is treated as a 64-bit floating point number.
How do you know that they are whole numbers? What you see on-screen with
Excel etc is not necessarily what you've got. If you format your column
with 0 decimal places, 4750456000708.123 will show as 4750456000708

However, whether they are whole numbers or not, you still have a problem
on the Python side:
...
But when I do import the pyExcelerator converts them to something like
this:
4.7504560002e+12
4.7504560007e+12
4.7504560007e+12
4.7504560003e+12
No it doesn't. It converts the XLS file data to Python float type --
64-bit floating point numbers. There is no loss of precision.

What you are seeing are different visual presentations of the *same*
object. Perhaps this will explain:

| >>for x in (4750456000708.0, 4750456000708.123):
| ... print x, str(x), repr(x)
| ...
| 4.75045600071e+012 4.75045600071e+012 4750456000708.0
| 4.75045600071e+012 4.75045600071e+012 4750456000708.123
| >>>
>
How I understand it's because the integer value is too big.
A 12-digit integer is too big for what?
If the type
of the items was string, then all would be fine, but I can't control
the file content.

The question is, how can I import the integers in normal format.
The answer is, there is no such thing as "normal format". Normality,
like beauty, is in the eye of the beholder. You have a value, how you
format it for display depends on your purpose. If what you want is to
see the most precise representation of what you've got, then use repr().

HTH,
John
Jan 10 '07 #2
Thank you, the repr() function helped me a lot.

v = unicode(values[(row_idx, col_idx)])
if v.endswith('e+12'):
v = repr(values[(row_idx, col_idx)])

Jan 10 '07 #3

Gacha wrote:
Thank you, the repr() function helped me a lot.

v = unicode(values[(row_idx, col_idx)])
if v.endswith('e+12'):
v = repr(values[(row_idx, col_idx)])
That endswith() looks rather suspicious ... what if it's +11 or +13,
and shouldn't it have a zero in it, like "+012" ??

Here's a possible replacement -- I say possible because you have been
rather coy about what you are actually trying to do.

value = values[(row_idx, col_idx)])
if isinstance(value, float):
v = repr(value)
else:
v = unicode(value)

HTH
John

Jan 10 '07 #4
John Machin wrote:
Here's a possible replacement -- I say possible because you have been
rather coy about what you are actually trying to do.

value = values[(row_idx, col_idx)])
if isinstance(value, float):
v = repr(value)
else:
v = unicode(value)

HTH
John
My final result:

value = values[(row_idx, col_idx)]
if isinstance(value, float) and
re.match('^\d+\.\d+e\+\d+$',unicode(value)):
v = repr(value)
else:
v = unicode(value)

Jan 16 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Marco Aschwanden | last post by:
Hi, Yesterday I placed a bug report on PyExcelerators-Sourceforge-page... but I am not so sure anymore, whether this is really a bug - I could imagine that I missed something, but I don't see...
3
by: tkpmep | last post by:
I downloaded PyExcelerator.zip as I need to write some data into Excel files, and tried unsuccessfully to install it. I unzipped the files into C:/Python24/Lib/site-packages/PyExcelerator, and in a...
2
by: tkpmep | last post by:
I have just installed PyExcelerator, and now want to use it to read Excel spreadsheets with a variable number of rows and columns and with multiple sheets. Unfortunately, no documentation seems to...
1
by: tkpmep | last post by:
I write data to Excel files using PyExcelerator 0.6.3.a and have done so successfully for small files (10-15 cells). I'm experiencing an error when writing a big chunk of data (10,000 cells) to...
1
by: Gerry | last post by:
I'd like some cell to be a Blue "ABCDE". Here's come code thatv tries various values for pattern_for_colour and font.colour_index, to no avail. Can anyone suggest the right way to set colours?...
5
by: susan | last post by:
Hi, I'm new of Python, and this problem stucked me whole day but can't be solved. I use python 2.4.3, which is download from cygwin packages. Then I downloaded pyexcelerator-0.5.3a, unzip it, ...
3
by: tkpmep | last post by:
My program creates three lists: the first has dates expressed as strings, the second has floats that are strictly positive, and the third has floats that are strictly negative. I have no trouble...
1
by: aneesh.goel.rbtx | last post by:
I'm using pyExcelerator to take a folder of CSV files and create Excel workbooks for all of them, then generate an Excel workbook with the data from all of them. Everything up until here works...
0
by: Stephen Brown | last post by:
Yes indeed, pyExcelerator does support reading data from excel spreadsheets. An example of how to do this is included in the file xls2csv-gerry.py under the directory ......
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.