How do I write files to my local drive when using Google Colab? - excel

I have a set of data I want to write to an Excel file. I'm using Google Colab, and while I successfully use the following snippet to import files into my notebook...
from google.colab import files
uploaded = files.upload()
...I can't seem to figure out how to write files to my local drive. I'm using the xlwt library to write the data to an Excel file, as follows:
wb.save('Washington_1791.xls')
It completes the task without throwing an error, but I'm not sure of the save location, and I need to get it to save to my local drive. Google gives me lots of suggestions on how to import from the local drive, but not how to save.

Any files written by your Python code will be on the disk of the virtual machine on which the code is running: if you want to get the files to your local disk, you will have to download them explicitly.
To do this, go to the Files tab in the left pane (click the (>) in the upper left to open the pane). Within that file viewer you can right-click any file and choose "Download".

Related

Where can I find the path of my excel file in colab?

I upload a excel file in the homepage of colab
However, when I want to read this file in my code, it always shows " No such file or directory" no matter I change the path of file
df = pd.read_excel('/content/drive/My Drive/thesis_bio/0419_combined_biodyes.xlsx', header=0)
How to find the correct path of my file, I check most directory, but havent found yet...
Just connect to google drive from colab if you have not and go to that location where file is present and hover on to that file. You will see 3 dots next to the file, just click on it and you will see an option "copy path", click it and it will be copied to your clipboard.

How to save python pptx on colab

Is there a way to save the Python pptx file on Google drive or desktop?
I tried Prs.save() to save the pptx file, but it doesn't work.
Your presentation will be saving to the Files panel on the left of Colab:
From here you can download the saved presentation file.
If you want to save to Google Drive you need to mount the drive (icon is at the top of the Files panel) and then simply append the relevant path to your file name when saving:
prs.save("/content/drive/My Drive/.../presentation.pptx")

How can I load data from an external drive into a Jupyter notebook on MacOs?

I have running code in my home directory in Jupyter notebook. I'd like to import some data from an external drive, as the data is too large to be stored on my local drive. I am unable to import this data into my notebook.
If you can browse to the data using Finder, you should be able to load the data into your Jupyter notebook.
Your code to open a file in your notebook probably looks something like this:
with open("data.txt","r") as dataFile:
You need to replace data.txt with the path to the file you want to open.
One way to get the path name is to navigate to the file in Finder and then drag the file into your Terminal. The path to the file will then be pasted into the command prompt of the Terminal.
The path may look something like this: /Volumes/Remove/Data/bigfile.txt
You can also navigate to the file using the cd command in the Terminal.
You may even be able to drag the file directly into your Jupyter notebook to get the path.
Hope this helps!

Need to monitor user downloads folder for new .xlsx files, then open Excel, save the file, and close Excel

At work I use a tool that requires me to download a .xlsx file, open it, then save it to remove the workbook protection. I'd like to create a script that automatically opens and saves any .xlsx files that are saved in the downloads folder.
I'm assuming PowerShell is the right tool to use. I found this article that explains how to do something similar, but I need help with configuring the parameters.
https://social.technet.microsoft.com/Forums/scriptcenter/en-US/1faa97e0-2288-4bb2-b8ad-283df32779d4/can-i-open-an-excel-workbook-when-files-with-a-certain-extension-are-saved-in-a-specified-folder?forum=ITCG
What I need is for the script to monitor the $env:USERPROFILE\downloads folder for any .xlsx files. Then I need it to open that file in Excel (preferably in a minimized window), save it with the same filename, then close Excel.
You can use IO.FileSystemWatcher to monitor a directory. See Start-FileSystemWatcher for an example implementation in PowerShell.

How to measure the sizes of files inside an open .xlsx file

Can anyone help with the following :
How to measure the sizes of the different files inside an .xlsx file while it is open for write in my excel?
As you already noted with your [zip] tag, .xlsx is actually a zip file. Therefore, even if the file is opened you still access it read-only and get the information you want.
I usually use the great Total Commander (the shareware is fully functional): navigate to the file and press Ctrl-Shift-ArrowUp and in the opposite window a new tab will open. In this tab, you can browse the .xlsx (or any other MS Office ZIP for that matter) as a normal folder, i.e. seeing it contents/file sizes/etc.

Resources