how do i add different sizes of the values into a panda data frame at the same time?

pubid = 1
keywords = [2, 2,3]

df = pd.DataFrame({'pubid': pubid, 'keywords': keywords})
print(df)

Prints:

   pubid  keywords
0      1         2
1      1         2
2      1         3

Then you can use pd.concat to add data to existing DataFrame:

pubid = 6
keywords = [10, 11]

df = pd.concat([df, pd.DataFrame({'pubid': pubid, 'keywords': keywords})]).reset_index(drop=True)
print(df)

Prints:

   pubid  keywords
0      1         2
1      1         2
2      1         3
3      6        10
4      6        11

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top