1 回答

TA貢獻(xiàn)1816條經(jīng)驗(yàn) 獲得超6個(gè)贊
如果我理解你很好,你應(yīng)該首先通過(guò)將列表拆分為均勻長(zhǎng)的子列表來(lái)準(zhǔn)備你的數(shù)據(jù):list_of_links
import pandas as pd
rqsts_catdogtiger = ['Cat' , 'Dog', 'Tiger']
list_of_links = [...] # your list of links
n = int(len(list_of_links) / len(rqsts_catdogtiger))
list_of_list_of_links = [list_of_links[i:i + n] for i in range(0, len(list_of_links), n)]
之后,您可以輕松地制作.如果希望列表位于列中,請(qǐng)使用以下代碼:pandas.DataFrameLinks
>>> df = pd.DataFrame({'Request Name': rqsts_catdogtiger, 'Links': list_of_list_of_links})
>>> print(df)
Request Name Links
0 Cat [https://www.polygon.com/2020/3/19/21187025/ca...
1 Dog [https://nypost.com/2020/03/19/second-dog-in-h...
2 Tiger [https://tvrain.ru/teleshow/doma_pogovorim/tig...
如果要在一個(gè)長(zhǎng)字符串中包含鏈接,其中每個(gè)鏈接都用逗號(hào)分隔,請(qǐng)使用以下代碼:
>>> df = pd.DataFrame({'Request Name': rqsts_catdogtiger, 'Links': [', '.join([url for url in l_of_urls]) for l_of_urls in list_of_list_of_links]})
>>> print(df)
Request Name Links
0 Cat https://www.polygon.com/2020/3/19/21187025/cat...
1 Dog https://nypost.com/2020/03/19/second-dog-in-ho...
2 Tiger https://tvrain.ru/teleshow/doma_pogovorim/tige...
添加回答
舉報(bào)