安装程序
title_list = list('ABCDE')
url_list = list('VWXYZ')
category_list = 'dog cat bird fish lizard'.split()
traffic_list = 'red green yellow blue amber'.split()
revenue_list = range(5, 10)
value_list = range(100, 600, 100)
zip
如果所有列表的长度都相等,则此选项有效。
data = [title_list, url_list, category_list,
traffic_list, revenue_list, value_list]
cols = 'title url category traffic revenue price'.split()
pd.DataFrame(dict(zip(cols, data)))
title url category traffic revenue price
0 A V dog red 5 100
1 B W cat green 6 200
2 C X bird yellow 7 300
3 D Y fish blue 8 400
4 E Z lizard amber 9 500
如果长度不同
data = [title_list, url_list, category_list,
traffic_list, revenue_list, value_list]
cols = 'title url category traffic revenue price'.split()
pd.DataFrame(list(zip(*data)), columns=cols)
title url category traffic revenue price
0 A V dog red 5 100
1 B W cat green 6 200
2 C X bird yellow 7 300
3 D Y fish blue 8 400
4 E Z lizard amber 9 500