TypeError: ‘DataFrame’ object is not callable. Very simple code to read

  combinations, dataframe, list, python

I’m a beginner in Python, so please bear with me here. I appreciate all the help as well.

I would like to generate all possible combinations between two lists. I have an excel file that I’m bringing into the code, where the first two columns are populated with text in the cells("List 1" is the first column. "List 2" is the second column, with "List 2" having the longer list). I’m treating each column as its own list. Any help here would be greatly appreciated as well.

I’m running into an error with my simple code, which is this:

TypeError                                 Traceback (most recent call last)
<ipython-input-6-e72255edcda8> in <module>
      1 #have the two column lists in the excel file be recognized as lists in python
----> 2 list_1 = list(df1('List 1'))
      3 list_2 = list(df1('List 2'))
      4 all_combinations = []
      5 

TypeError: 'DataFrame' object is not callable

Here’s my code currently:

lists_combos = "combos_list.csv
import itertools
import pandas as pd
from itertools import permutations
from itertools import combinations
df1 = pd.read_csv(lists_combos)
list_1 = list(df1('List 1'))
list_2 = list(df1('List 2'))
all_combinations = []

list_2_permutations = itertools.permutations(list_2, len(list_1))

for each_permutation in list_2_permutations:
   zipped = zip(each_permutation, list_1)
   all_combinations.append(list(zipped))

print(all_combinations)

I would also like to make an output .csv file of the possible combinations between the two lists. Any help here would be greatly appreciated as well. Thanks.

Source: Python Questions

LEAVE A COMMENT