Вы можете использовать рекурсию с простым классом:
import csv
_, *data = csv.reader(open('filename.csv'))
new_data = [[a, b, c if not c.isdigit() else int(c), *d] for a, b, c, *d in data]
class Tree:
def __init__(self, _d, _start='null'):
self.head, _next = [i for i in _d if i[2] == _start], 1 if _start == 'null' else _start+1
self.children = (lambda x:None if not x else Tree(_d, _next))([i for i in _d if i[2] == _next])
Теперь Tree
создает структуру, которая хранит твиты в соответствии с "уровнем", указанным reply_status_id
:
d = Tree(new_data)
print(d.head)
print(d.children.head)
print(d.children.children.head)
print(d.children.children.children.head)
Вывод:
[['1', 'a', 'null', 'dahgfsjhg']]
[['2', 'b', 1, 'fcjgvujhgjhk'], ['4', 'd', 1, 'giuyhewikuhieuhi']]
[['3', 'c', 2, 'ououoijoskjfpokpo']]
[['5', 'e', 3, 'hkjhkjlkjljlkjlj']]