0

I am attempting to implement an Apyori / Association rule. I am struggling to correctly format the dataset for the model to consume. The documentation outlines that model requires

  • Each item is separated with a tab.

  • Each transaction is separated with a line feed code. See below or linked documentation

     transactions = [
         ['beer', 'nuts'],
         ['beer', 'cheese'],
     ]
    

My Tab separated items are coming through fine from the source, but I am struggling to add in a line feed between each transaction/List.

import adodbapi

conn = adodbapi.connect("Provider=MSOLAP.8; \
    Data Source='powerbi://api.powerbi.com/v1.0/myorg/MyPowerBIWorskpace'; \
    Initial Catalog='MyPowerBIReportNameinService'")

curs = conn.cursor()

dmv = """
EVALUATE SELECTCOLUMNS( 'Table Schema List of Lists','Table Schema List of Lists'[Tables_Clean_Names])
"""
curs.execute(dmv)
results = curs.fetchall()
#Below is the relevant code for the question


testlist =[]
for row in results:
    rowlist=[]
    a =row[0]
    rowlist.append(a)
    testlist.append(rowlist)
    #apppend a new line leads to additional list item  followed by coma
    testlist.append('\n')
conn.close()

Using and append (testlist.append('\n')) leads to an additional comma (see screenshot).

enter image description here

How can I add a newline with the trailing comma?

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
Steve
  • 475
  • 4
  • 12
  • 25
  • 1
    Does this answer your question? [Printing list elements on separate lines in Python](https://stackoverflow.com/questions/6167731/printing-list-elements-on-separate-lines-in-python) – mkrieger1 Sep 25 '22 at 08:48

0 Answers0