How to save a dataframe as a csv in a managed folder?

Solved!
Usersyed
Level 3
How to save a dataframe as a csv in a managed folder?

Hi all,

I want to save a dataframe as a csv in a managed folder inside my Dataiku project.

To read files from the managed folder, I usually use this code (because my script is deployed as an API inside Dataiku)

folder_path = folders[0]

path_of_file = os.path.join(folder_path, "file_name_with_extension")

df = pd.read_csv(path_of_file)

But how about saving a dataframe as a csv in the managed folder?

Can someone please help me with this?

Thanks!


Operating system used: Windows

0 Kudos
1 Solution
FlorentD
Developer Advocate

Hi,

Maybe I am wrong or don't understand the problem.

You have nothing more to do than writing to the managed folder, with the pandas library. You just have to change the name of the file, if you want to.

Did you try?

 

 

path_of_copy = os.path.join(folder_path, "copy_file_name_with_extension")
df.to_csv(path_of_copy)

 

 

 

Hope this helps.

Best

View solution in original post

0 Kudos
3 Replies
FlorentD
Developer Advocate

Hi,

Maybe I am wrong or don't understand the problem.

You have nothing more to do than writing to the managed folder, with the pandas library. You just have to change the name of the file, if you want to.

Did you try?

 

 

path_of_copy = os.path.join(folder_path, "copy_file_name_with_extension")
df.to_csv(path_of_copy)

 

 

 

Hope this helps.

Best

0 Kudos
ssuhas76
Level 3

Does the same code work for storing a csv file into a managed folder. I need to do this via Python API endpoint function

0 Kudos
Turribeach

When you say via Python API endpoint function what exactly do you mean? API endpoint function means to me an API you have developed and deployed in the Dataiku API node. If you donโ€™t mean that please explain. 

0 Kudos