我有一个数据帧的列表,我迭代它们,使用一个pandaps重命名所有的列/索引df.重命名方法。在df.rename(
{
'vol': 'Volume Sales',
'val': 'Value Sales',
},
index={
't1': info['literal_periods'][0],
't2': info['literal_periods'][1],
'acv': '% ACV Distribution',
'aic': 'Average Items Carried',
'tdp': 'Total Distribution Points',
'vol': 'Volume Sales',
'psl': 'Promo Sales',
'Share of AIC': '{} share of {} AIC'.format(
info['name'], info['p1']),
'Share of TDP': '{} share of {} TDP'.format(
info['name'], info['p1']),
'Target Product': info['name'],
'target product': info['name'],
},
columns={
't1':
info['literal_periods'][0],
't2':
info['literal_periods'][1],
'promo change':
'% change from ya',
'non promo change':
'% change from ya',
'sales change':
'% change from ya',
'val':
'Value Sales (£)',
'vol':
'Volume Sales (L)',
'volsu':
'Volume Sales (units)',
'litres per unit':
'litres/unit',
't2 Promo Sales':
'{} Promo Sales'.format(info['literal_periods'][1]),
't2 Non-Promo Sales':
'{} Non Promo Sales'.format(info['literal_periods'][1]),
't2 Total Sales':
'{} Total Sales'.format(info['literal_periods'][1])
},
inplace=True)
对于某些表,它似乎可以完美地工作,部分地适用于其他表,而对于某些表则完全不起作用。有人知道为什么会这样吗?
例如,在一个包含aic的数据框中,aic索引没有被正确地重命名,即使在同一个df中,“vol”列被正确地映射为“vol Sales”。。。在