combinations of all rows and cols from a dataframe
marc nicole
mk1853387 at gmail.com
Wed Mar 29 14:40:00 EDT 2023
Hello everyone,
Given a dataframe like this:
2 6
8 5
I want to yield the following list of lists:
[ [[2],[6,5]],
[[2],[6]],
[[2],[5]],
[[8],[6,5]],
[[8],[6]],
[[8],[5]],
[[6],[2,8]],
[[6],[8]],
[[6],[2]],
[[5],[2,8]],
[[5],[2]],
[[5],[8]],
[[6,5],[2,8]] ]
I have written the following (which doesn't yield the expected results)
import pandas as pd
> from itertools import combinations
> import numpy as np
> resList=[]
> resListTmp=[]
> resListTmp2=[]
> dataframe =
> pd.read_excel("C:\\Users\\user\\Desktop\\testData.xlsx",index_col=False,header=None)
for i in range(0, len(dataframe)+1):
> for j in range(0, len(dataframe.columns)):
> for k in range (0,len(dataframe)+1):
> for xVals in list(combinations(dataframe.iloc[k:i,j], i)):
> if list(xVals) not in resListTmp:
> resListTmp.append(list(xVals))
> resListTmp2.append(resListTmp)
> resList.append(resListTmp2)
> print(resList)
>
What is wrong with my code?
More information about the Python-list
mailing list