используйте to_dict
. Посмотрите, работает ли это для вас
DF
Month1 Month2 Month3 Month4 Month5 Month6
Name
Credit 4644.5 11142 6198.33 2830.48 5886 8381.5
No.oftransactions 8.0 4 6.00 14.00 6 4.0
['No.Of Transaction{} : {}'.format(key,value) for key, value in df.to_dict(orient='index')['No.oftransactions'].items()]
['{} : {}'.format(key,value) for key, value in df.to_dict(orient='index')['Credit'].items()]
выход
['No.Of TransactionMonth1 : 8.0',
'No.Of TransactionMonth2 : 4.0',
'No.Of TransactionMonth3 : 6.0',
'No.Of TransactionMonth4 : 14.0',
'No.Of TransactionMonth5 : 6.0',
'No.Of TransactionMonth6 : 4.0']
['Month1 : 4644.5',
'Month2 : 11142.0',
'Month3 : 6198.33',
'Month4 : 2830.48',
'Month5 : 5886.0',
'Month6 : 8381.5']
Обновление
DF
Month2 Month3 Month4 Month5 Month6
Name
Credit 11142 6198.33 2830.48 5886 8381.5
No.oftransactions 4 6.00 14.00 6 4.0
credit = df.to_dict(orient='index')['Credit']
transaction = df.to_dict(orient='index')['No.oftransactions']
['{} : {}'.format('Month{}'.format(key),credit.get('Month{}'.format(key))) for key in range(1,6) ]
выход
Out[455]:
['Month1 : None',
'Month2 : 11142.0',
'Month3 : 6198.33',
'Month4 : 2830.48',
'Month5 : 5886.0']
['No.Of Transaction{} : {}'.format('Month{}'.format(key),transaction.get('Month{}'.format(key))) for key in range(1,6)]
выход
['No.Of TransactionMonth1 : None',
'No.Of TransactionMonth2 : 4.0',
'No.Of TransactionMonth3 : 6.0',
'No.Of TransactionMonth4 : 14.0',
'No.Of TransactionMonth5 : 6.0']