Search code examples
pythonpandasdataframedictionaryyfinance

How to export YahooQuery Dict type modules to CSV from AttributeError: 'dict' object has no attribute 'to_csv'?


AttributeError: 'dict' object has no attribute 'to_csv' occurs with the following:

import pandas as pd
from yahooquery import Ticker
symbols = ['AAPL','GOOG','MSFT'] 
faang = Ticker(symbols)
faang.asset_profile
df = (faang.asset_profile)
df.to_csv('output.csv', mode='a', index=True, header=True)

It happens with a lot of Dict type YahooQuery modules. Changing faang.asset_profile to faang.valuation_measures (a pandas:DataFrame type) works great.


Solution

  • This seems to be working:

    import pandas as pd
    from yahooquery import Ticker
    symbols = ['AAPL','GOOG','MSFT'] 
    faang = Ticker(symbols)
    faang.asset_profile
    df = pd.DataFrame(faang.asset_profile).T
    df.to_csv('output.csv', mode='a', index=True, header=True)