您可以像这样用熊猫来做:
import pandas as pd a = {'Job1': {'2017-01-10': [44, 33, 11, 75, 22]}, 'Job2': {'2017-01-05': [25, 25, 0, 100, 25], '2017-01-10': [50, 50, 0, 100, 25]}, 'Job3': {'2017-01-03': [44, 22, 22, 50, 22], '2017-01-04': [66, 36, 30, 54, 22], '2017-01-06': [88, 52, 36, 59, 22], '2017-01-10': [132, 68, 64, 51, 22], '2017-01-02': [22, 9, 13, 40, 22], '2017-01-08': [110, 52, 58, 47, 22]}, 'Job4': {'2017-01-10': [25, 25, 0, 100, 25]}} df = pd.DataFrame(data=a) df = df.fillna(' ').T df
输出:
如果只需要列表的第一个元素:
df = df.applymap(lambda x: x[0] if type(x)==list else x) df
如果要将其转换为HTML表,可以使用如下.to_html()
方法:
print df.to_html()
输出:
2017-01-02 | 2017-01-03 | 2017-01-04 | 2017-01-05 | 2017-01-06 | 2017-01-08 | 2017-01-10 | |
---|---|---|---|---|---|---|---|
Job1 | 44 | ||||||
Job2 | 25 | 50 | |||||
Job3 | 22 | 44 | 66 | 88 | 110 | 132 | |
Job4 | 25 |