简体   繁体   中英

Trying to a save file in local folder in python

    home_dir = os.path.abspath(os.curdir)  
    stock_file_path = os.path.join(home_dir, 'data', 'stock_data.csv')
    stock_data.(stock_file_path, index=True)


    stock_data.(stock_file_path, index=True)
               ^
    SyntaxError: invalid syntax

Stock_data contains some data, taken from yahoo API, I want save it in my local folder as csv file. It is showing Invalid Syntax.

Use

stock_data.to_csv(stock_file_path, index=True)

You forgot the method name and I'm just going to assume you're using a Pandas DF from the context and params.

docs

It should be so. You need to add to_csv after stock_data:

home_dir = os.path.abspath(os.curdir)  
stock_file_path = os.path.join(home_dir, 'data', 'stock_data.csv')
stock_data.to_csv(stock_file_path, index=True)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM