Pandas: A problem

Created on 5 Apr 2019  ·  6Comments  ·  Source: pandas-dev/pandas

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.

Usage Question

Most helpful comment

the CNY0704/05/19.csv bit looks iffy as does .strftime("Y%M%D")

All 6 comments

@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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

songololo picture songololo  ·  3Comments

amelio-vazquez-reina picture amelio-vazquez-reina  ·  3Comments

venuktan picture venuktan  ·  3Comments

scls19fr picture scls19fr  ·  3Comments

ericdf picture ericdf  ·  3Comments