为什么我会收到此ImportError但函数仍然起作用?

时间:2019-07-04 11:16:13

标签: python jupyter-notebook

我有个函数,它假定将给定目录中的所有.csv文件合并到单个数据帧中。在这里:

                                    "Here is your Marksheet"


        <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
        §                                                                               §
        §                                                                               §
        §                         Bermingham Board                                      §
        §                                                                               §
        §                                                                               §
        §    Examination      Annual 2019                                               §
        §                                                                               §
        §    Name             John Michael                                              §
        §                                                                               §
        §    F.Name           Brad Michael                                              §
        §                                                                               §
        §    School/Private   Bermingham High School                                    §
        §                                                                               §
        §    Group            Science                                                   §
        §                                                                               §
        §   _________________________________________________________________________   §
        §  |                                                                         |  §
        §  |                               Subjects                                  |  §
        §  |_________________________________________________________________________|  §
        §  |            Component             |                 Marks                |  §
        §  |__________________________________|______________________________________|  §
        §  |            Maths                 |                 76/100              |  §
        §  |__________________________________|______________________________________|  §
        §  |            English               |                 81/100              |  §
        §  |__________________________________|______________________________________|  §
        §                                                                               §
        §                                                                               §
        §                                Grand Total 157 out of 200                      §
        §                                                                               §
        §                                         _______                               §
        §                                        |       |                              §
        §                                Grade   |   A   |                              §
        §                                        |_______|                              §
        §                                                                               §
        §                                       Waseem Munir                            §
        §                                _________________________                      §
        §                                Controller of Examination                      §
        §                                                                               §
        § Dated:04-07-2019                                                              §
        §                                                                               §
        §                                                                               §
        <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

        Do you want to repeat?

        Yes or No:

我收到以下ImportError:

import pandas as pd, os
from functools import reduce


def merge_csv_files(target_input_directory, target_output_path):
    list_of_data_files = os.listdir(target_input_directory)
    list_of_data_frames = []
    for file in list_of_data_files:
        new_df = pd.read_csv(target_output_path + '\\' + file)
        list_of_data_frames.append(new_df)
    df_merged = reduce(lambda left, right: pd.merge(left, right, on=['Data'], how='outer', sort=True),
                       list_of_data_frames)
    df_merged.to_csv(target_output_path + '\\' + 'merged.csv', index=False)

尽管如此,我的函数似乎可以正常工作,并且得到了想要的东西,但是它返回错误的事实令人沮丧,我想知道这种情况发生的原因。

这是目录树:

enter image description here

0 个答案:

没有答案