Reading csv/excel file from any folder in computer (Python/Jupyter notebook) - jupyter-notebook

Is there any way to read any file using the "copy path as" option and paste that path in the jupyter notebook?

Related

How can I ask jupyter to automatically revert when file has changed on disk

Hello I am using jupyter-lab with the jupytext extension.
This extension allows you to --sync different format so that you can edit say a Rmd file that will automatically be converted to ipynb
This ipynb file is loaded in jupyter
To update the file opened in jupyter I have to click on "save", I then get the following message
I then have to click on revert to update from disk.
Is there a way so that the file on disk is automatically "reloaded" each time it changed or say every second and that It s "reverted" automatically ?

What R command to use to force download files from iCloud

On a mac using iCloud file optimization, large files that are seldom used are uploaded to iCloud and only a small pointer file is left. When I look for the file in Finder, I see the file name and to the left is an icon that indicates that the file is in the cloud. To access the file, I click on the icon and the file is downloaded. With the file.exist command, R returns FALSE for the existence of the file. But after some research I found that the file link is stored in a directory below ~/Library/Mobile\ Documents/com~apple~CloudDocsand the file name is changed to xxx.icloud where xxx is the original file name.
Here's an example of the path to a a directory that holds a .icloud file from a shell in my mac
/Users/gcn/Library/Mobile Documents/com~apple~CloudDocs/Documents/workspace/nutmod/data-raw/NutrientData
I can query for the existence of the file with exists(xxx.icloud). But how do I tell my mac to download the iCloud file and then read it in? Using something like read.table or read.csv doesn't work because the pointer file is not csv.
You can read a csv file directly from a iCloud folder on the Mac by using the path to that folder. Get the path by finding it in the finder. Then right click on the filename at the bottom of the finder window where it shows all the folders leading to the file and choose: Copy "YourFile" as Pathname.
That path will look something like this:
"/Users/NAME/Library/Mobile
Documents/com~apple~CloudDoc/Docs/YourFile.csv"
Use that in your read code:
iCloudDat <- read_csv("/Users/NAME/Library/Mobile Documents/com~apple~CloudDocs/Documents/YourFileName.csv")
That should work.
If the extension isn't .txt or .csv read.table and read.csv won't work.
you have to download the file and extract the tables to a readable format.
you can download the file using download.file() which is is the utils basic library.

How to save Jupyter notebooks from GitHub

When I download an ipynb file using the RAW button in GitHub it displays the text (json) in the browser.
Should I just copy this text into a file and name it xxx.ipynb? What's the best way to do it?
First click on Raw
Then, press ctrl+s to save it as .ipynb (Note that you'll have to manually type '.ipynb' after the file name to make this work, as files from GitHub are saved as text files as default.)
Open jupyter notebook
Go to location where you saved .ipynb file
Open file, you will see the code
Hope this helps
Here is the Lifesaver Extension developed by me for both
Chrome
Firefox
The project is open-sourced here.
The extension not only opens github hosted notebooks in Colab but also in nbviewer!
And you can open the github repo from Colab and nbviewer
And go to nbviewer from Colab and github
Works all 3 ways!!
A new feature of opening new notebooks in one-click is already developed in the master branch, just need to push it to the extension platforms :)
Firefox extension
Chrome extension
The following steps worked for me:
Click on Raw in git repository.
Save the file. The file was saved as *.ipynb.txt format for me.
Then, in the jupyter directory tree (not in local directory), I selected, removed the .txt at the end and renamed the file as *.ipynb.
Finally I was able to run the file as jupyter notebook.
Note that, when I tried to rename the *.txt file in local directory to *.ipynb, it did not work. This had to be renamed in directory in jupyter itself.
True to 2020:
Click Download
Wait for JSON to finish loding in your browser
Ctrl S (save as .txt file)
remove .txt extension
Run locally
I saved the file following the instructions from this post. My destination however was a folder on google drive. I opened google drive on my browser and located the file. From there, I renamed the name of my file by just removing the txt extension, leaving the ipynb extension. That worked for me.

How to save a file into a directory in Jupyter notebook?

I invoke "jupyter notebook" under:
[abigail#localhost anaconda3]$ jupyter notebook
By default, it saves to the directory of anaconda3/ with an extension of "ipynb" when I click "File" => "Save".
How to save it to a directory under anaconda3/, instead of the default location? There is not a "save as" command in notebook?
You can save a notebook to a location of your choice by using the "File" -> "Download as" -> "Notebook (.ipynb)" option from the menu.
Alternatively you can start your notebook server from a different directory and it will save all notebooks to that directory.
A third option is to navigate to the directory you want the notebook to be saved to in the tree view "http://127.0.0.1:8888/tree" prior to creating the notebook.
There are two methods:
1.You can use the magic command %notebook to save as ipynb
%notebook "directory/to/file/filename.ipynb"
2.You can use the magic command %%writefile to save as py file
%%writefile "directory/to/file/filename.py"
In the second method, you should put this command at the top of the cell, otherwise it will throw an error.
It is easiest to select a destination before you create a program using Jupyter Notebook; as then you do not run into this issue.
However, since you have already made a program, one possible solution is to make a copy of the file, move it to your desired location, and then delete the old file. Before doing this, ensure that you have saved it first, otherwise data might be lost.

How to create .jl file in IJulia

I am very new to julia. I have just installed ipython and Ijulia. But every time I saved my file from ipython notebook, the format of the saved file is always .ipynb. I don't know if I can saved my file as .jl file. Or could anyone tell me how to create .jl file through ipython notebook. I have googled but seems like no one talks about it.
.ipynb is the JSON-based Jupyter notebook format, with conventions for storing code cells and associated metadata and data (such as inline images). Jupyter is designed as a fully-integrated interactive environment, not "just" a text editor, and as such the file format requires extra information. To create a .jl file, use a text editor or an ide such as Juno.

Resources