Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Pasted tables from Jupyter to StackOverflow get ill-formatted

Consider the code:

df = pd.DataFrame({
    "name":["john","jim","eric","jim","john","jim","jim","eric","eric","john"],
    "category":["a","b","c","b","a","b","c","c","a","c"],
    "amount":[100,200,13,23,40,2,43,92,83,1]
})
df

When I copy the output, I get a not nicely formatted table here on StackOverflow:

name    category    amount  sum count
0   john    a   100 140 2
1   jim b   200 225 3
2   eric    c   13  105 2
3   jim b   23  225 3
4   john    a   40  140 2
5   jim b   2   225 3
6   jim c   43  43  1
7   eric    c   92  105 2
8   eric    a   83  83  1
9   john    c   1   1   1

How to fix this problem?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

from an ipython terminal session I can paste:

In [73]: df
Out[73]: 
   name category  amount
0  john        a     100
1   jim        b     200
2  eric        c      13
3   jim        b      23
4  john        a      40
5   jim        b       2
6   jim        c      43
7  eric        c      92
8  eric        a      83
9  john        c       1

From a notebook, it looks like print(df) gives a better result:

   name category  amount
0  john        a     100
1   jim        b     200
2  eric        c      13
3   jim        b      23
4  john        a      40
5   jim        b       2
6   jim        c      43
7  eric        c      92
8  eric        a      83
9  john        c       1

The copy selection should be a solid color block.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading