0

I have a simple question that I could not find anywhere the solution. I'm sorry if this is already asked here.

My code is simple:

s = pd.Series(np.random.rand(150))

I just want to print it and see all of its output:

print(s)

The output:

>>> print(s)
0      0.580686
1      0.508062
2      0.184946
3      0.275074
4      0.831654
5      0.080571
6      0.153813
7      0.088002
8      0.082935
9      0.513361
10     0.064965
11     0.325820
12     0.933384
13     0.605428
14     0.121554
15     0.767311
16     0.476030
17     0.423448
18     0.028080
19     0.905429
20     0.185212
21     0.770636
22     0.569428
23     0.294643
24     0.482404
25     0.217303
26     0.406958
27     0.893210
28     0.863044
29     0.270612
         ...   
120    0.221621
121    0.077798
122    0.154689
123    0.155532
124    0.828792
125    0.564565
126    0.714583
127    0.913120
128    0.632600
129    0.115126
130    0.543111
131    0.420206
132    0.135349
133    0.912911
134    0.788410
135    0.685158
136    0.282509
137    0.545654
138    0.074851
139    0.247384
140    0.244246
141    0.798268
142    0.348548
143    0.775883
144    0.114062
145    0.246298
146    0.216241
147    0.639255
148    0.902388
149    0.416965
Length: 150, dtype: float64

As you can see it is dividing my output from line 29 to 120. I want the whole output to be written.

I've tried this in the Ubuntu terminal, IPython Console 6.5.0, both running as a saved file & running on the interactive shells.

Then, I wondered what if I wanted the output in a file:

import pandas as pd
import numpy as np

with open('test.txt', 'w') as myfile:
    s = pd.Series(np.random.randn(150))
    myfile.write(str(s))

.. I checked the test.txt. Output is still the same, divided with '...'.

How can I make python to print all of the output?

9
  • Use s.to_csv('test.txt', index=False) Commented Aug 31, 2018 at 8:44
  • It's "convenience" formatting so if you print massive frames/series/arrays etc... you don't sit and wait hours for your computer to display it... myfile.write(s.to_string()) will write to the file the full string for your series.... Commented Aug 31, 2018 at 8:45
  • Um... think there's also a good Q/A on pd.set_option regarding this as well... Commented Aug 31, 2018 at 8:46
  • @JonClements I see. Thanks for clarifying. Commented Aug 31, 2018 at 8:47
  • @Teoman imagine if you had a 400 column 1 million row dataframe and you printed that... you'd not get your computer back for a bit and you wouldn't want to see all that anyway... So it works on the basis if you do want that, you have to be really explicit about it... It'll try and print the first N and last N (with the ...) between and the first N columns and last N columns as above... so you get an idea of what's there... Generally setting the number of columns to None (or really high number) so you can scroll across columns makes sense but you'll rarely want to see all rows :) Commented Aug 31, 2018 at 8:50

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.