I suspect OP wants all those 0's to print, no matter how many there are. No array(
nor )
and no ellipsis ...
EDIT:
See comment from @John:
For anyone happening upon this in the future, numpy.savetxt()
does what the OP wants without having to create the strings by hand.
Guess:
Try ','.join([str(_) for _ in data[i][5:]])
In full:
row = [{'Field1': data[i][:3], 'Field2': data[i][3:5], 'LongField': ','.join([str(_) for _ in data[i][5:]])}]
Related to this answer.
Help us:
What kind of array are you using? Can you show us more code? Or tell output of: type(data[0])
EDIT
OP clarified what kind of array and how long it is:
It's a numpy.array
(or one dimension of the ndarray
; same str treatment)
And it's 2,984 long.
Apparently a str version of numpy.array
will truncate all but first 3 and last 3 elements when the array has 1000 elements or more
999 elements:
str(numpy.array(range(1000)))
>>[ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
>> 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
>> 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
>> 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
>> 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
>> 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
etc...
1000 elements:
str(numpy.array(range(1001)))
>>'[ 0 1 2 ..., 998 999 1000]'
So I think my original recommendation should work, forcing it to the string representation you want. I think CSV DictWriter
should take care of quoting.
','.join([str(_) for _ in numpy.array(range(2987))])
EDIT
Explaining my answer:
So you are not giving DictWriter a string -- it must infer the string. I assume DictWriter will use Python str
function. As the documentation says, the str
function will:
Return a string containing a nicely printable representation of an object.
I suppose numpy
developers thought that an array
with >999 elements would not be very "printable"
So above 1000 they probably have the __str__
function return a "summarized" version, which only shows first 3 elements and last 3 elements.
Instead of letting DictWriter or the str
give you a string, you can create exactly the string you want. I believe the string you want is just all the elements of the array separated by a comma, that's what this code does:
','.join([str(_) for _ in [1,2,3]])
','.join()
will "concatenate" all the elements on a comma; elements must be strings
- the
[str(_) for _ in [1,2,3]]
will convert the individual elements to strings (required for the join to work)