简体   繁体   English

如何使用 Jupyter Notebooks 进行打印

[英]How to print with Jupyter Notebooks

I'm new to Jupyter Notebooks.我是 Jupyter Notebooks 的新手。 Taking a python for finance course, and right at the start ran into this problem.参加金融课程的python,一开始就遇到了这个问题。

import pandas as pd
import matplotlib.pyplot as plt

def test_run():
    df = pd.read_csv("C:/Users/James/Desktop/MSFT.csv")
    print(df)

this runs no errors, but just does not print anything under the cell.这不会运行任何错误,但不会在单元格下打印任何内容。 I know this must be a silly thing i'm not doing, but I can't figure it out, any help greatly appreciated.我知道这一定是我没有做的一件愚蠢的事情,但我无法弄清楚,非常感谢任何帮助。

If the above code is exactly what you're executing, then the code will not output anything.如果上面的代码正是你正在执行的,那么代码不会 output 任何东西。

You are defining a function, but not running that function.您正在定义 function,但未运行该 function。 The function (when run) will print something to the console (stdout). function(运行时)将在控制台(标准输出)上打印一些内容。 If run in a jupyter notebook, the output will display in the output cell.如果在 jupyter notebook 中运行,output 将显示在 output 单元格中。 However, you are not running the function.但是,您没有运行 function。

The below should print to the jupyter notebook下面应该打印到 jupyter notebook

import pandas as pd
import matplotlib.pyplot as plt

def test_run():
    df = pd.read_csv("C:/Users/James/Desktop/MSFT.csv")
    print(df)

test_run()  # run the function

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM