Python itertools组合库是否可以用于对象而不是列表?
例如,如何在以下数据上使用它?
Rahul - 20,000 - Mumbai
Shivani - 30,000 - Mumbai
Akash - 40,000 - Bangalore
我希望得到姓名和薪资的所有可能组合。如何使用
combinations
实现此功能?假设数据已使用 pd.read_csv
读取并存储。当前的代码 -
import pandas as pd
import itertools
df = pd.read_csv('stack.csv')
print (df)
for L in range(0, len(df)+1):
for subset in itertools.combinations(df['Name'], L):
print (subset)
输出
Name Salary City
0 Rahul 20000 Mumbai
1 Shivani 30000 Mumbai
2 Akash 40000 Bangalore
()
('Rahul',)
('Shivani',)
('Akash',)
('Rahul', 'Shivani')
('Rahul', 'Akash')
('Shivani', 'Akash')
('Rahul', 'Shivani', 'Akash')
Process finished with exit code 0
如何在这些组合中添加薪资?