Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 13981

Fastest method to post a pandas dataframe from Jupyter Notebooks into a Stack Overflow problem?

$
0
0

I just posted my first Stack Overflow question. I spent ages formatting a pandas dataframe table in the post. What steps do you use to post a pandas dataframe in a Stack Overflow question?

I searched for an answer and found this detailed post: How to make good reproducible pandas examples. I followed the instructions and used pd.read_clipboard, but I still had to spend a significant amount of time formatting the table to make it look correct.

I also found a similar question with only one answer with a downvote: How to display a pandas dataframe on a Stack Overflow question body.

I tried to copy the dataframe from Jupyter and pasting it into a Blockquote. As mentioned, I also ran pd.read_clipboard('\s\s+') in Jupyter to copy it to the clipboard and then posted it into a Blockquote. I also tried creating a table and posting the values in the table. All of these methods required that I tweak the formatting to make it look properly formatted.

Here is an example dataframe to use:

df = pd.DataFrame(    [['Captain', 'Crunch', 72],     ['Trix', 36, 'Rabbit'],     ['Count', 'Chocula', 41],     ['Tony', 54, 'Tiger'],     ['Buzz', 28, 'Bee'],     ['Toucan', 'Sam', 38]],    columns=['first_name', 'last_name', 'age'])

Viewing all articles
Browse latest Browse all 13981

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>