V
V
vladmoi2020-08-30 17:18:30
Python
vladmoi, 2020-08-30 17:18:30

How to make a table from plain text in excel using python?

And so, there is text with camera numbers and their location. You need to make a table with two columns (see photo) 5f4bb3a3556a4142258925.pngFor this, I chose a python. I do not know if this is the right choice, but in any case I will be glad to hear possible solutions. Here is the text itself:
north
camera1
camera2
camera3
camera4
west
camera5
camera6
camera7
camera9

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Gornostaev, 2020-08-30
@vladmoi

def groups_to_columns(lines):
    directions = ['north', 'south', 'west', 'east']
    current_direction = None
    for line in lines:
        data = line.strip()
        if data in directions:
            current_direction = data
        else:
            yield current_direction, data


with open('data.txt') as fh:
    for direction, camera in groups_to_columns(fh):
        # Запись в xls

R
Ronald McDonald, 2020-08-30
@Zoominger

g: openpyxl
I use, the flight is normal.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question