简体   繁体   中英

Create pandas DataFrame from two lists with same keys

I have two lists of tuples with the same keys as shown below. How can I create a pandas DataFrame with the key as the index and the values in columns?

l1 = [('jan', 1.2), ('feb', 1.3), ('mar', 1.1)]
l2 = [('jan', 1.1), ('feb', 1.2), ('mar', 1.3)]
df = pd.DataFrame([dict(l1), dict(l2)]).transpose()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM