create dataframe in pandas, why the creation leads to the clear of the zip of tuples?

Question:

import pandas as pd
sentences=['aaa','bbb','ccc']
labels = [1,2,3]
infos = zip(sentences , labels)
df_synthesize = pd.DataFrame(infos, columns = ['content','label'])
print(df_synthesize)
print(list(infos))

I use the infos to initialize the dataframe, however, after the creation, the infos becomes null list.

print(list(infos))

[]

It is quite weird, why this happens?

pandas version : 1.1.5

Asked By: yanachen

||

Answers:

Try this. panddas: 1.1.5

import pandas as pd
sentences=['aaa','bbb','ccc']
labels = [1,2,3]
infos = list(zip(sentences , labels))
       // ^----------------------------------- clue
df_synthesize = pd.DataFrame(infos, columns = ['content','label'])
print(df_synthesize)

Output

  content  label
0     aaa      1
1     bbb      2
2     ccc      3
Answered By: top talent
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.