List of LISTS of tuples to Pandas dataframe?
Just flatten your list into a list of tuples (your initial list contains a sublists of tuples):
In [1251]: tupList = [[('commentID', 'commentText', 'date'), ('123456', 'blahblahblah', '2019')], [('45678', 'hello world', '2018'), ('0', 'text', '2017')]]
In [1252]: pd.DataFrame([t for lst in tupList for t in lst])
Out[1252]:
0 1 2
0 commentID commentText date
1 123456 blahblahblah 2019
2 45678 hello world 2018
3 0 text 2017
A shorter code this:
from itertools import chain
import pandas as pd
tupList = [[('commentID', 'commentText', 'date'), ('123456', 'blahblahblah', '2019')], [('45678', 'hello world', '2018'), ('0', 'text', '2017')]]
new_list = [x for x in chain.from_iterable(tupList)]
df = pd.DataFrame.from_records(new_list)
Edit
You can make the list comprehension directly in the from_records
function.
tupList = [[('commentID', 'commentText', 'date'), ('123456', 'blahblahblah', '2019')], [('45678', 'hello world', '2018'), ('0', 'text', '2017')]]
print(pd.DataFrame(sum(tupList,[])))
Output
0 1 2
0 commentID commentText date
1 123456 blahblahblah 2019
2 45678 hello world 2018
3 0 text 2017