dingaro
dingaro

Reputation: 2342

How to create loop or function which give all possible combinations of data from Data Frame in Python Pandas?

I have DataFrame like below:

df = pd.DataFrame({"code" : [1,1,2,2,3], "value" : [10, 11, 11, 11, 30]})

And I need to create loop which in result give me all combinations of code x value so:

1 10
1 11
2 11
3 30

How can I do that ? It can be also as a def

Upvotes: 0

Views: 86

Answers (2)

KHEIREDDINE ATTALA
KHEIREDDINE ATTALA

Reputation: 1

If I did understand your question correctly :

for index,row in df.iterrows():
     print("{} {}".format(row["code"],row["value"]))

Please feel free to explain your question further if that is not what you needed. You may provide more examples as well

Upvotes: 0

Karoo
Karoo

Reputation: 552

IIUC, you simply need to use drop_duplicates().

Upvotes: 1

Related Questions