How can I save a file into a folder in Jupyter Notebook? - csv

I'm working on a ipynb file, here I created a dataframe and converted it into a csv file. I want create this file in a particular existing folder.
For example:
df = pd.DataFrame(#Something)
df.to_csv("data.csv")
But I want create this csv file in a folder contained in the jupyter notebook i'm working on

Related

gulp how to use copied files in the destination folder in the same task

With Gulp 4, i have a task to copy an original file atleast 3 times and then modify each new file, while keeping the original file intact.
How to achieve the following steps:
select json file through src
copy json file through dest
select the destination json file since the file name is the same
make changes in the new json file
repeat 1-4 on another loop

Applescript help: Move files to folders according to a CSV file

I am looking for an AppleScript that moves files in a single directory into new folders based on info provided in a CSV file, where the columns are A) Filename with extension B) New folder title. Thank you.

problam wuth Uploading csv file

I'm trying to upload a csv file to R and when I do its write this messege:
this is the scv file , Itried to upload the file, but I don't know if I can here,

How can I create a zip?

How can I add files and zip the folder?
So far, using zipfile, I’m able to create a zip.
How can I create a folder to add files and zip the folder?
You can do what you want by following these steps:
To create a folder, use os.mkdir like this:
import os
os.mkdir('spam') # your folder name
then you can write files to it or use shutil.copy to make copies of existent files.
# to write files:
with open('./spam/eggs.txt', 'w') as fp: # creates a text file in spam named eggs.txt
fp.write('hello') # write hello
# to copy files
import shutil
shutil.copy('eggs.txt', './spam/eggs.txt') # copy eggs.txt from the current working dir to spam folder
then to zip the folder, you had the right idea, to use zipfile like this:
from zipfile import ZipFile, ZIP_DEFLATED
zipfp = ZipFile('spam.zip', 'w', ZIP_DEFLATED) # create a new zip file named spam.zip
for root, dirname, files in os.walk('./spam'): # walk in the spam folder
[zipfp.write(os.path.join('./spam',file)) for file in files] # write them to the zip file
zipfp.close()
A complete example:
import os
from zipfile import ZipFile, ZIP_DEFLATED
os.mkdir('spam')
with open('./spam/eggs.txt', 'w') as fp:
fp.write('hello')
with ZipFile('spam.zip', 'w', ZIP_DEFLATED) as zipfp:
for root, dirname, files in os.walk('./spam'):
[zipfp.write(os.path.join('./spam',file)) for file in files]
The result of this code is it produces a compressed folder named spam.zip and in the zip file, there's a txt file named eggs.txt which contains the text 'hello'.
To clarify for the OP:
[zipfp.write(os.path.join('./spam',file)) for file in files]
is equivalent to:
for file in files:
zipfp.write(os.path.join('./spam',file))
it's just simpler to write it using list comprehension.

want to unzip a specific file from zipped file

I have a directory where zipped file is placed. I want to extract it but I need only xml document from it. I am able to extract whole file but I need only xml file. I need it in perlscript only on windows platform.