Sign up to take part
Registered users can ask their own questions, contribute to discussions, and be part of the Community!
Registered users can ask their own questions, contribute to discussions, and be part of the Community!
Hi,
I have a dataframe in my DSS workflow which I want to change and store in a non-csv file within a folder.
Assume my dataframe is called df and for the example you can recreate is as follows
df = pd.DataFrame({"a": [1,2,3,4,5], "b": [6,7,8,9,10], "c": [11,12,13,14,15]})
I now want to add a few lines of comment above the dataframe and then save the file automatically in a folder.
Firstly, I have taken my dataset and load it into a folder ("my_input_folder") with the DSS recipe "Export to folder" calling the file df.csv. Then I have added a python script which reads the file, adds the comments and output it in another folder ("my_output_folder"). The code is below but it didn't get what I wanted. Could you please help?
# -*- coding: utf-8 -*-
import dataiku
import pandas as pd, numpy as np
from dataiku import pandasutils as pdu
import os.path
# Recipe inputs
folder_path = dataiku.Folder("my_input_folder").get_path()
path_of_csv = os.path.join(folder_path, "df.csv")
# Recipe outputs
output2 = dataiku.Folder("my_output_folder")
output2_path = output2.get_path()
completeName = os.path.join(folder_path, "df.csv")
file1 = open(completeName, "w")
toFile = raw_input("# This is my first comment\n This is my other comment \n") # I need to write two comments on two different rows
file1.write(toFile)
file1.close()
dirPath2 = os.path.join(output2_path,file1)
Thank you!