Home > front end >  New to Python - Trying to output a dataframe to csv from Input
New to Python - Trying to output a dataframe to csv from Input

Time:01-25

Good Morning/ Afternoon

I'm relatively new, learning some python for the finance It world. Trying to figure out some inputs > outputs for data.

My goal is to create a CSV from the ticket input only thing missing is it won't create a new file from said "ticker"

import yfinance as yf
start_date = '2020-01-01'
end_date = '2023-01-20'
ticker = input("Enter Ticker :")
data = yf.download(ticker, start_date, end_date)
print(data.tail())

# Export data to a CSV file
data.to_csv = ( '.csv')

CodePudding user response:

As Matt said, you should use:

data.to_csv("name_of_file.csv")

If you wish your code to have variable csv name:

input_name = "IBM"
data.to_csv(f"{input_name}.csv")

You need to define input_name though.

  • Related