in Education by
Jupyter notebooks (Python) return the value of the last variable in a cell in a pretty printed format. Using print(df) won't output the dataframe pretty printed. But this will pretty print df to the Jupyter notebook: In[1]: import pandas as pd import numpy as np filename = "Umsaetze.csv" csv_file = f"~/Desktop/{filename}" # read csv into DataFrame df = pd.read_csv(csv_file, sep=";", decimal=",") df How can I print several variables in a pretty printed format? This here will only print df3 in a pretty printed format: In[2]: df1 df2 df3 Edit Here is the answer (from: Show DataFrame as table in iPython Notebook) from IPython.display import display, HTML # Assuming that dataframes df1 and df2 are already defined: print("Dataframe 1:") display(df1.head()) print("Dataframe 2:") display(df2.head()) JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
You can use tabulate to output a table in pretty-printed format: import pandas as pd import numpy as np from tabulate import tabulate df = pd.DataFrame(np.random.randint(0, 10, size=(5, 4)), columns = list('ABCD')) print(tabulate(df, headers = 'keys', tablefmt = 'psql')) +----+-----+-----+-----+-----+ | | A | B | C | D | |----+-----+-----+-----+-----| | 0 | 2 | 1 | 3 | 0 | | 1 | 1 | 9 | 1 | 6 | | 2 | 9 | 8 | 6 | 3 | | 3 | 0 | 7 | 3 | 2 | | 4 | 5 | 9 | 7 | 3 | +----+-----+-----+-----+-----+ Edit: To print multiple data frames in pretty-print format from a single cell in Jupyter Notebook, use the following: from IPython.core.interactiveshell import InteractiveShell InteractiveShell.ast_node_interactivity = 'all' df df

Related questions

0 votes
    Visual Studio Code has option to connect to jupyter notebook. When it's done I can execute my script ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 24, 2022 in Education by JackTerrance
0 votes
    I'm trying to open up a PDF as an image using Wand. If I run the code below in Jupyter Notebook ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 21, 2022 in Education by JackTerrance
0 votes
    I have recently quoted a Deep Learning VM from Google Cloud. DLVM provides a link to the jupyter notebook ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 17, 2022 in Education by JackTerrance
0 votes
    import pandas as pd from itertools import combinations, product, permutations MH_P= ["Maria Herrera"] OP_P= ["Oscar ... i solve it? Select the correct answer from above options...
asked Jan 11, 2022 in Education by JackTerrance
0 votes
    I have several csv columns that store lottery numbers and some other info, like date when the number was ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 6, 2022 in Education by JackTerrance
0 votes
    How can we pretty-print JSON in a shell script?...
asked Jan 11, 2021 in Technology by JackTerrance
0 votes
    I have a dataframe with which if a cell has a value other than "." then I need python to return ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 3, 2022 in Education by JackTerrance
0 votes
    I've recently seen quite a bit of the following pattern in Python: class Foo: pass class Bar: ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jun 2, 2022 in Education by JackTerrance
0 votes
    I'm working on a mini text role playing game where you must survive dinner with the king. I'm ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 8, 2022 in Education by JackTerrance
0 votes
    I started learning python a few months back, so i don't know alot of terms still. This program ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 2, 2022 in Education by JackTerrance
0 votes
    I'm trying to make a function that will compare multiple variables to an integer and output a string of three ... like this possible? Select the correct answer from above options...
asked Jan 30, 2022 in Education by JackTerrance
0 votes
    In a function, How to create and use a global variable? How can I use it in other functions? Is it compulsory ... it in a function? Select the correct answer from above options...
asked Jan 24, 2022 in Education by JackTerrance
0 votes
    I have a python variable how can I see that it's unsigned 32 bit or signed 16 bit, etc? Select the correct answer from above options...
asked Jan 22, 2022 in Education by JackTerrance
0 votes
    I'm using Python to open a text document: text_file = open("Output.txt", "w") text_file.write("Purchase Amount: ... how to do this? Select the correct answer from above options...
asked Feb 4, 2022 in Education by JackTerrance
0 votes
    Alright, I know how to print variables and strings. But how can I print something like "My string" card.price ... variable card.price). Select the correct answer from above options...
asked Jan 26, 2022 in Education by JackTerrance
...