I have a few .ipynb notebooks with similar outputs (time series data). I want to export all the outputs from all the notebooks to a .txt file. If that is complicated to do, then one txt file for each of the notebooks is fine too.
Asked
Active
Viewed 674 times
1
-
Could you elaborate on how your data is outputted? Are they numpy arrays, lists, pandas DataFrames, ...? – lcdumort Feb 08 '22 at 14:18
-
It is outputed as a pandas dataframe. – schakraborty Feb 09 '22 at 00:45
-
1I have tried this. '%%capture cap --no-stderr print(xyz)' 'with open('output.txt', 'w') as f: f.write(cap.stdout)' However, the output dataframe of one of the notebooks, for example, has 6032 rows x 158 columns. And the txt file created only shows the first few rows as when you print it in the jupyter notebook. But I need all of the output dataframe rows to be included in the txt file. @icdumort – schakraborty Feb 09 '22 at 01:17
-
I think you could use this `pd.set_option('display.max_rows', None) `, however 6032 is really a lot. I'm not sure if it will be decently displayed – lcdumort Feb 09 '22 at 01:19
-
Thank you. Do I use this along with the code I mentioned? If so, which cell should I add this code in? – schakraborty Feb 09 '22 at 01:25
-
This would be a pandas settings, so ideally immediately after importing your packages. The rest of your code remains unaltered. Once you've ran it, the setting remains unchanged until you change it manually or restart the kernel/notebook – lcdumort Feb 09 '22 at 01:28
-
1Thank you so much :). This worked. I used it here: %%capture cap --no-stderr pd.set_option('display.max_rows', None) print(xyz) – schakraborty Feb 09 '22 at 01:31
-
you're welcome! I've summarized our discussion in an answer for other people to easily follow up. If it worked for you, feel free to select it as the answer. – lcdumort Feb 09 '22 at 02:04
1 Answers
0
As you mentioned yourself in the comments, you can save it as a .txt file by using:
%%capture cap --no-stderr
By using pd.set_option('display.max_rows', None)
you can then assure that all rows are shown in your jupyter notebook.

lcdumort
- 599
- 3
- 20