“asyncio.run() cannot be called from a running event loop” when using Jupyter Notebook

The asyncio.run() documentation says: This function cannot be called when another asyncio event loop is running in the same thread. In your case, jupyter (IPython ≥ 7.0) is already running an event loop: You can now use async/await at the top level in the IPython terminal and in the notebook, it should — in most of the … Read more

How can I left justify text in a pandas DataFrame column in an IPython notebook

If you’re willing to use another library, tabulate will do this – $ pip install tabulate and then from tabulate import tabulate df = pd.DataFrame ({‘Text’: [‘abcdef’, ‘x’], ‘Value’: [12.34, 4.2]}) print(tabulate(df, showindex=False, headers=df.columns)) Text Value —— ——- abcdef 12.34 x 4.2 It has various other output formats also.

Pyspark – converting json string to DataFrame

You can do the following newJson = ‘{“Name”:”something”,”Url”:”https://stackoverflow.com”,”Author”:”jangcy”,”BlogEntries”:100,”Caller”:”jangcy”}’ df = spark.read.json(sc.parallelize([newJson])) df.show(truncate=False) which should give +——+———–+——+———+————————-+ |Author|BlogEntries|Caller|Name |Url | +——+———–+——+———+————————-+ |jangcy|100 |jangcy|something|https://stackoverflow.com| +——+———–+——+———+————————-+

How to run a Jupyter notebook with Python code automatically on a daily basis?

Update recently I came across papermill which is for executing and parameterizing notebooks. https://github.com/nteract/papermill papermill local/input.ipynb s3://bkt/output.ipynb -p alpha 0.6 -p l1_ratio 0.1 This seems better than nbconvert, because you can use parameters. You still have to trigger this command with a scheduler. Below is an example with cron on Ubuntu. Old Answer nbconvert –execute … Read more

Using %matplotlib notebook after %matplotlib inline in Jupyter Notebook doesn’t work

You just have the wrong order of your commands. A backend should be set before importing pyplot in jupyter. Or in other words, after changing the backend, pyplot needs to be imported again. Therefore call %matplotlib … prior to importing pyplot. In first cell: %matplotlib inline import matplotlib.pyplot as plt plt.plot([1,1.6,3]) In second cell: %matplotlib … Read more

Overwrite previous output in jupyter notebook

@cel is right: ipython notebook clear cell output in code Using the clear_output() gives makes your Notebook have the jitters, though. I recommend using the display() function as well, like this (Python 2.7): from random import uniform import time from IPython.display import display, clear_output def black_box(): i = 1 while True: clear_output(wait=True) display(‘Iteration ‘+str(i)+’ Score: … Read more