0

I'm trying to make an etl script but when running the extract function im getting this error 'DataFrame' object has no attribute 'append'

the function

import pandas as pd
from datetime import datetime
import glob

def extract_from_csv(file_to_process):
    dataframe = pd.read_csv(file_to_process)
    return dataframe

def extract():
    extracted_data = pd.DataFrame(columns=["Term", "Amount"]) 
    
    for csvfile in glob.glob("*.csv"):
        extracted_data = extracted_data.append(extract_from_csv(csvfile), ignore_index=True)
        
    return extracted_data

I don't know what to try this is function i have been using for the past two etl scripts

Ivan Vinogradov
  • 4,269
  • 6
  • 29
  • 39

1 Answers1

0

Here is a clear way you could achieve your result:

import pandas as pd
from datetime import datetime
import glob

def read_csv(csv_file):
    return pd.read_csv(csv_file, columns=["Term", "Amount"])

def extract():
    dfs = [read_csv(f) for f in glob.glob('*.csv')]
    return pd.concat(dfs, ignore_index=True)

Eyad Sibai
  • 811
  • 7
  • 21