我目前正在使用一个脚本来执行大量的CSV复制和粘贴操作。 (我们正在做一个产品导入文件的Magento)使用变量时遇到问题
def select_cell(m):
return 'row.'+ m
def mageimport(f,x): #let x = table_size let y = color or wood_stain
sku_copy = [row.sku for index, row in f.iterrows() if type(select_cell(x)) != float]
option1 = [x for index, row in f.iterrows() if type(select_cell(x)) != float]
option2 = [select_cell(x) for index, row in f.iterrows() if type(select_cell(x)) != float]
df = {}
df = {'_super_products_sku':sku_copy, '_super_attribute_code':option1, '_super_attribute_option':option2}
return df
如果我究竟使用代码如上所述,我把关于x的任何值返回一个字符串,而不是从我的数据帧的小区。我知道问题来自select_cell()
函数,但我不知道如何绕过它。
如果我用row.table_size
替换select_cell()
,则信息出来正确。我可以做到这一点,但我宁愿让这个功能起作用。
任何意见表示赞赏。
是'x'整数==表的长度,还是字符串'“table_size”',或其他? –
@HughBothwell f是我所命名的数据框,x应该是列名中的任何一个。所以,x.table_size给了我具有产品大小的列。我想将它应用于其他专栏:f.colors,f.wood_stain等等。 – whyth3