我正在使用Python进行数据清理。我有下面的工作流程来调用我的所有函数

  if __name__ == "__main__":

       data_file, hash_file, cols = read_file()
       survey_data, cleaned_hash_file = format_files(data_file, hash_file, cols)
       survey_data, cleaned_hash_file = rename_columns(survey_data, cleaned_hash_file)
       survey_data, cleaned_hash_file = data_transformation_stage_1(survey_data, cleaned_hash_file)
       observation, survey_data, cleaned_hash_file = data_transformation_stage_2(survey_data, cleaned_hash_file)
       observation, survey_data, cleaned_hash_file = data_transformation_stage_3(observation, survey_data, cleaned_hash_file)
       observation, survey_data, cleaned_hash_file = observation_date_fill(observation, survey_data, cleaned_hash_file)
       write_file(observation, survey_data, cleaned_hash_file)

。。所以observationsurvey_datacleaned_hash_filedata_filehash_filecols、都是每个函数中使用的数据帧。

最佳答案

尝试遍历函数。它假设当前迭代的输入与上一次迭代的输出具有相同的顺序:

funcs = [read_file, format_files, rename_columns, data_transformation_stage_1, data_transformation_stage_2, data_transformation_stage_3, observation_date_fill, write_file]

output = []
for func in funcs:
    output = func(*output)

10-06 15:50