我创建了一个数据帧列表,我必须为其获取相同数据帧的名称以使用它来命名新生成的数据帧。我想从“for-loop”中命名新生成的数据帧,类似于(表示)它们各自的数据帧。
list_containing_dataframes = [Furnishings, Labels, Accessories, Binders, Supplies, Phones, Tables]
for i in list_containing_dataframes:
# some operations done on 'i' to generate new dataframes !
# let's save the newly generated dataframes!
newly_generated_dataframes.to_csv(str(i)+'_forecast' , index = False, encoding = 'utf-8')
# .to_csv() function is being used to save the dataframes in csv format in google colab!
# Expected - The name of newly generated dataframes to be 'name of dataframe #operated on'+'forecast'.
# example- Tables_forecast, where df_Tables is the name of Dataframe operated on!
# Error - str(i) in '.to_csv()' function prints the name along with the index column which becomes so long that it throws error 'name too long!'
# I just want the name of the dataframe along with string '_forecast' attached to it!
为什么不将数据场放入字典并使用键来命名 csv:
dict_containing_dataframes = {'Furnishings': Furnishings, 'Labels': Labels, 'Accessories': Accessories, 'Binders': Binders, 'Supplies': Supplies, 'Phones': Phones, 'Tables': Tables}
for key, one_dataframe in dict_containing_dataframes.items()
newly_generated_dataframes.to_csv(key+'_forecast' , index = False, encoding = 'utf-8')
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句