16

I was trying to print this question: Groupby with User Defined Functions Pandas

My first attempt, using default settings from Safari, produced a column of text about 2 inches (5 cm) wide and truncated most of the code blocks. For example, this line

>>> people.groupby(lambda x: 'Group1' if people['b'].loc[x] > people['a'].loc[x] else 'Group2').sum()

printed as

>>> people.groupby(lambda x: 'Grou|

where the vertical bar represents about one pixel width of the p.

Printing in landscaped worked better, but there was still about a 2 inch (5 cm) margin on the left and a 4 inch (10 cm) margin on the right. There was more output:

>>> people.groupby(lambda x: 'Group1' if people['b'].l

but it was still missing a significant portion of the line.

I looked for a print button, but I did not find anything that seemed relevant.

I eventually copied the text into a plain text document and then printed that. That did not truncate the text, but it did lose a lot of the formatting.

7
  • 3
    The awful print formatting is probably a bug.
    – Laurel
    Commented Oct 31, 2018 at 20:06
  • Side note, Google Chrome does not appear to have that issue with formatting. Both this question and the linked one look fine and have all the relevant data there.
    – user4979686
    Commented Oct 31, 2018 at 21:06
  • If i remember right, copying the text into Notepad++ would retain the formatting
    – Ryolu
    Commented Nov 2, 2018 at 2:08
  • 3
    Just don't print at all, that's so last century.
    – Luuklag
    Commented Nov 2, 2018 at 7:50
  • @Luuklag Yes. But sometimes, work has restrictions about what you are allowed to do. Commented Nov 2, 2018 at 15:18
  • I think I would just click on the edit button, copy the markdown and save it somewhere. If I need it later, I can use my brain markdown parser or another software supported one. This way I can still copy and paste links :) Commented Nov 4, 2018 at 4:28
  • 1
    @Luuklag "Printing" also involves printing to a PDF, which can be handy at times.
    – Andreas
    Commented Nov 6, 2018 at 8:20

1 Answer 1

16

A third-party service called StackPrinter exists to help facilitate this scenario. You can simply put the question ID in to its site and it will generate a printer-friendly version of the question.

Disclaimer: I don't claim to know if this project actually works, but it exists as a resource.

2
  • It appears to work, as in all the code is on the page. +1.
    – Mooseman
    Commented Nov 3, 2018 at 10:40
  • It works, but the output looks absolutely horrible. It's a shame there isn't a way to get the benefit of Stack Exchange's nice layouts without having the comments truncated.
    – JBentley
    Commented May 30, 2019 at 13:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .