Excel Rows to sentences - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Data Science (https://python-forum.io/forum-44.html) +--- Thread: Excel Rows to sentences (/thread-12440.html) |
Excel Rows to sentences - spartak315 - Aug-24-2018 Hello I'm new to this forum, hopefully someone can provide some insight on what i'm trying to accomplish. Lets say i have an excel file with 5 rows and 2 columns. I want to place each of the rows into a string sentence. For example I want column1 and column2 to be added to a sentence.this is what i have coded so far: import pandas as pd; FILE_PATH = "C:\\Users\\apples.xls"; xl = pd.ExcelFile(FILE_PATH); df = xl.parse('testone'); apples = [] color =[] apples = list(df['apples']) color = list(df['color']) #for index, row in df.iterrows(): #print(index, row['apples'], row['color']) def f(string, n, c=0): if c < n: print(string) f(string, n, c=c + 1) f('this apple is{0} with color {0}'.format(apples,color), 3)desired output: Thanks in advanced,SP |