Python Forum
Excel Rows to sentences
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Excel Rows to sentences
#1
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.
Output:
apples color honeycrsp red gala red goldendel orange fuji red grannys green
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:
Output:
"this apple is honeycrsp with color red" "this apple is gala with color red" "this apple is goldendel with color orange" "this apple is fuji with color red" "this apple is grannys with color green"
Thanks in advanced,

SP
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Counting of rows in Excel Spreadsheet dakrantau 2 395 Sep-30-2020, 02:27 AM
Last Post: dakrantau
  Datasets of grammatically uncommon sentences? regstuff 3 547 Nov-03-2019, 07:02 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020