Hello
I use Python 3.7 to report errors when running this module:
import tushare
import pandas as pd
import datetime
#Step 1: Get the ticket code online
Ticket_Raw_Data = tushare.get_stock_basics()
tickets = Ticket_Raw_Data.index.tolist()
#Step 2: save the ticket code
data_today = datetime.datetime.today().strftime("Y%M%D")
File = "F:\\ticket\\data\\ticketa-list CN"+data_today+".csv"
Ticket_Raw_Data.to_csv(File)
print("saved.")
Operation error reporting
Traceback (most recent call last):
File "F:\ticket\programme\get-ticket-code.py", line 13, in <module>
Ticket_Raw_Data.to_csv(File)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\pandas\core\frame.py", line 1745, in to_csv
formatter.save()
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\pandas\io\formats\csvs.py", line 156, in save
compression=self.compression)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\lib\site-packages\pandas\io\common.py", line 400, in _get_handle
f = open(path_or_buf, mode, encoding=encoding)
FileNotFoundError: [Errno 2] No such file or directory: 'F:\\ticket\\data\\ticketa-list CNY0704/05/19.csv'
[Finished in 2.1s]
How to solve it? Help me. Thank you.
@stepfencurryxiao the github issues are meant for reporting potential bugs / enhancement requests, and not for general questions for help (but of course, the line between both is not always clear). For general usage questions, a Q&A forum like StackOverflow or the pydata mailing list is a better place to ask.
Further, I also recommend you to provide a minimal, reproducible example (see http://matthewrocklin.com/blog/work/2018/02/28/minimal-bug-reports for more explanation), also if you ask the question in one of the other fora.
As your error states, double check that File is specified correctly. And as @jorisvandenbossche mentioned, please directly further usage questions to the suggested fora.
My address is copied on the computer. It should be correct.
the CNY0704/05/19.csv bit looks iffy as does .strftime("Y%M%D")
Yeah, I don't know why.
@simonjayhawkins Thank you!
I changed my code according to what you said.
# -*- coding:utf-8 -*-
import tushare
import pandas as pd
import datetime
#Step 1: Get the ticket code online
Ticket_Raw_Data = tushare.get_stock_basics()
tickets = Ticket_Raw_Data.index.tolist()
#Step 2: save the ticket code
data_today = datetime.datetime.today().strftime("%Y%m%d")
File = "../data/ticket-list-CN/Ticket-list_" + data_today + ".csv"
Ticket_Raw_Data.to_csv((File),encoding='utf_8_sig')
print("saved.")
result:
saved.
[Finished in 4.1s]
The problem has been solved.Thank you very much. @jorisvandenbossche @mroeschke @simonjayhawkins @myles
Most helpful comment
the
CNY0704/05/19.csvbit looks iffy as does.strftime("Y%M%D")