【问题标题】:how to get file name when file is imported using pandas.read_csv使用 pandas.read_csv 导入文件时如何获取文件名
【发布时间】:2017-09-14 17:51:27
【问题描述】:

我正在编写大函数,我需要使用输入文件名来给出输出文件名。我尝试了一些东西

import pandas as pd
import os
input_file = pd.read_csv('my_file.csv',header=None)
input_file_name = os.basename(input_file)

但我无法取回文件名。 如何在此处检索“my_file”?

【问题讨论】:

    标签: pandas csv filenames


    【解决方案1】:
    def do_job(input_file):
        if not os.path.exists(input_file):
            sys.stderr.write("Error: '%s' does not exist"%input_file)
            sys.exit(1)
        input = pd.read_csv(input_file,header=None)
    
        # do many operations
    
        # so file name is stored in handle 'input_file'
        # I can give output file name using input_file
        output_name = 'Results_' + input_file
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-11-17
      • 2016-08-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-08
      相关资源
      最近更新 更多