Luigi: Output from Pandas DataFrame

Created on 17 Sep 2018  路  7Comments  路  Source: spotify/luigi

Hello guys. I'm new to using Luigi, so my question is probably pretty simple. I have a processing that is done through Pandas DataFrame, with that, I need the output to be the result of this DataFrame.
Here's an example of what I intend to do.

class HubTask(luigi.WrapperTask):
    def requires(self):
        for index, row in energy.get_files().iterrows():
            yield Process(id_arquivo = row['ID_CONTROLE_ARQ_CONVENIO_ICMS'])

class Process(luigi.Task):
    id_arquivo = luigi.Parameter()

    def requires(self):
        ...

    def run(self):
        ...

    def output(self):
        return self.data_frame.to_csv('../temp/process_{}'.format(self.id_arquivo))

How could this be done?

All 7 comments

You can just mark a local file target, i.e. wrapping the path in a LocalTarget like luigi.LocalTarget('../temp/process_{}'.format(self.id_arquivo))

Yes, @raycheung is correct. output()s should return a Target. So in the case of a df csv, you'd to_csv() near the end of your run() and it would reference your self.output().path.

Like this @dlstadther ?

def run(self):
        time.sleep(5)
        df_invoices = pd.read_csv('../data/notas.csv', sep=';')
        df_invoices.loc[df_invoices['ID_CONTROLE_ARQ_CONVENIO_ICMS'] == self.file_id]
        self.data_frame = df_invoices
        self.data_frame.to_csv()
        ...
def output(self):
        return luigi.LocalTarget('../temp/invoices_{}.csv'.format(self.file_id))

But I still have not understood the question of self.output().path

Generally seems ok.

Here's a sample gist i created and updated awhile back. The base level of it is a dataframe thing

That's right, thank you @dlstadther and @raycheung. My problem has been solved.

Glad we could help!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

fmorency picture fmorency  路  5Comments

gioelelm picture gioelelm  路  5Comments

kashifjt picture kashifjt  路  5Comments

guyneedhamblis picture guyneedhamblis  路  5Comments

alfonsomhc picture alfonsomhc  路  3Comments