提取数据框中列名的组合

时间:2016-11-18 02:17:08

标签: python-2.7 pandas

我有一个包含列' flow1,flow2,flow3'的数据框。 我需要从列中提取不同的订单。

df1 = pd.read_csv("Desktop/lab9/cleaning1/1160/flow.tsv", sep = "\t", header = None, na_values=[" "])
df1.columns = ['flow1', 'flow2', 'flow3']
for p in permutations(df1.columns, 3):
    print p

这是给我的

('flow1', 'flow2', 'flow3')
('flow1', 'flow3', 'flow2')
('flow2', 'flow1', 'flow3')
('flow2', 'flow3', 'flow1')
('flow3', 'flow1', 'flow2')
('flow3', 'flow2', 'flow1')

但我只需要:

('flow1', 'flow2', 'flow3')
('flow1', 'flow3', 'flow2')
('flow2', 'flow3', 'flow1')

1 个答案:

答案 0 :(得分:0)

你误解了数学运算符。

使用from itertools import combinations代替permutations