1 votes

Class Creation ValueError: No engine for filetype: 'csv'

Learning to create classes. I try to create a class that you import stock quotes from Yahoo, and export them to files .xlsx and .csv. The script initially developed as a function operates correctly, however, the version that I have developed as a class, to me it returns an error I don't understand. The class is this:

class ImportadorExportadorYahoo (object):
    start = "2000-1-4"   
    end = date.today()

    def __init__(self, nombre, ticker, fichero_excel=None, fichero_csv=None): 
        #self.start = start
        #self.end = end
        self.nombre = nombre
        self.ticker = ticker
        self.fichero_excel = fichero_excel
        self.fichero_csv = fichero_csv

    def actualizar(self):     
        df = pd_data.DataReader(ticker, "yahoo", self.start, self.end)
        print ("\nCotizaciones ", nombre," \n", df[:3])    
        df.to_excel (self.fichero_excel)   
        df.to_csv (self.fichero_csv)  

os.chdir("G:/Py_2019/Py_micartera_POO/Ficheros_Yahoo")

"""Nombres de columnas del fichero csv: "lista_nombres" y "lista_tickers" """
df = pd.read_csv("lista_valores.csv")
data = df[df["ID"] == "Y"]
for i in range(0,data.shape[0]):
    nombre = data["nombres"][i]
    ticker = data["tickers"][i]
    fichero_excel = data["ficheros_xlsx"][i] 
    fichero_csv = data["ficheros_csv"][i] 
    obj = ImportadorExportadorYahoo(nombre, ticker, fichero_excel, fichero_csv)
    obj.actualizar()

In this link https://github.com/akitxu/Aprendiendo-GitHub

Is accessible the notebook "Clase_ImportarExportar_Yahoo.ipynb", and inside the folder "Files" is the file "lista_valores.csv"

The error returned is:

ValueError: No engine for filetype: 'csv'

what can be the cause?. I would appreciate your help.

Indeed, there was an error in the file "lista_valores.csv", but only affects the name of the file .csv that will be created in the export. Yahoo search the makes with the tickers of the field "tickers" of the file lista_valores.csv". The ticker "dow_jons" is "^GSPC". I note that this ticker is not outputting any error running.

start = "2000-1-4"   
end = date.today()
df = pd_data.DataReader("^GSPC", "yahoo", start, end)
df[:3]

However, the class I continues giving the same error.

I have tested the script in spyder, and I returns the same error.

2voto

ChemaCortes Points 5050

In the file "lista_valores.csv" there is a gazapo. If you'll notice, it leaves you good results until you get to the line of Dow Jones, which fails. There appears the CSV file "dow_jones.csv" that does not exist, you should put "dow_jons.csv".

The motor (engine) excel tries to read the file. As it is not found, returns as reference None, an object that does not have the attribute csv, which is what it says the first error:

OptionError: "No such keys(s): 'io.excel.csv.writer'"

In its turn produces another error:

ValueError: No engine for filetype: 'csv'

Actually, it appears that they are messages of much help. Renames the file or modifies the file "lista_valores.csv" to not give this error.

HolaDevs.com

HolaDevs is an online community of programmers and software lovers.
You can check other people responses or create a new question if you don't find a solution

Powered by:

X