Python Forum
Working with text data
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Working with text data
#3
Hey, thanks a lot for the support!
I know openpyxl, have been working with it before, it’s just that I have never worked with data in this format, i.e. all information in rows and only one single column… My idea was to extract those specific rows, interview_number, speaker, date, and then create new columns so that they are all split up. However, I haven’t even been successful at extracting those rows. What I’d ideally do is establish that all the rows follow the same format, interview number, speaker, date text, and then loop over interview numbers 1 to 400 to repeat the process. I have been unsuccessfully trying something along those lines:

for row in rows:
    sheet.append(row)
    
for row in sheet.iter_rows(min_row=1, min_col=1, max_row=6, max_col=3):
    for cell in row:
        print(cell.value, end=" ")
    print()    

book.save('iterbyrows.xlsx')
However, I don’t know how to tell Python which rows “are special” to me, i.e. the first 3 rows after an empty row, interview number, speaker, date. Shall I loop over the interview number? Or use the fact that between interviews there is an empty row?

If I looped trough the rows how could I tell Python which ones to extract?

file = "enter_path_to_file_here"
wb = openpyxl.load_workbook(file, read_only=True)
ws = wb.active

for row in ws.iter_rows("E"):
    for cell in row:
        if cell.value == "interview":
            print(ws.cell(row=cell.row, column=2).value) 
I’m honestly at my wits’ end.
Reply


Messages In This Thread
Working with text data - by APK - Aug-21-2020, 08:28 AM
RE: Working with text data - by Larz60+ - Aug-21-2020, 01:34 PM
RE: Working with text data - by APK - Aug-21-2020, 03:21 PM
RE: Working with text data - by Larz60+ - Aug-21-2020, 09:51 PM
RE: Working with text data - by buran - Aug-22-2020, 04:48 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Login Module Help - Comparing data in a text file to data held in a variable KeziaKar 0 2,712 Mar-08-2018, 11:41 AM
Last Post: KeziaKar

Forum Jump:

User Panel Messages

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