更改`row`的值

时间:2017-10-16 00:18:36

标签: python pandas

array of function pointer

def multiple_dfs(item, sheets, *args): """ Put multiple dataframes into one xlsx sheet """ writer, row = args[:2] response = send_request(item).content df = pd.read_csv(io.StringIO(response.decode('utf-8'))) df.to_excel(writer, sheets, startrow=row, index=False) row += len(df.index) + 2 def create_and_update_worksheets(): """ Add 'Player statistics' if the worksheet is not in file_name. Otherwise, it will update the worksheet itself. """ os.chdir(os.path.dirname(os.path.abspath(__file__))) writer = pd.ExcelWriter(file_name, engine='openpyxl') for key, value in worksheets: --> row = 0 if isinstance(value, dict): values = value.values() for item in values: --> multiple_dfs(item, key, writer, row) else: multiple_dfs(value, key, writer, row) for sheet in writer.sheets.values(): resize_columns(sheet) writer.save() writer.close() 函数中有两个箭头。为什么create_and_update_worksheets在第二个箭头的for循环中总是等于零?它应该输入row函数并更改multiple_dfs的值。我试图把代码放在不同的地方,但它没有改变。我不再有其他想法了。

1 个答案:

答案 0 :(得分:0)

你不能改变那样的参数值。

 ...
   ...
  return len(df.index) + 2

 ...
   ...
    row = multiple_dfs(item, key, writer, row)