本文介绍了获取列表列表到Pandas DataFrame中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将电子表格的内容读入熊猫. DataNitro具有一种返回矩形单元格选择作为列表列表的方法.所以

I am reading contents of a spreadsheet into pandas. DataNitro has a method that returns a rectangular selection of cells as a list of lists. So

table = Cell("A1").table

给予

table = [['Heading1', 'Heading2'], [1 , 2], [3, 4]]

headers = table.pop(0) # gives the headers as list and leaves data

我正忙着编写代码来翻译此内容,但我猜想它是如此简单,因此必须有执行此操作的方法.无法在文档中找到它.任何可以简化此方法的指针吗?

I am busy writing code to translate this, but my guess is that it is such a simple use that there must be method to do this. Cant seem to find it in documentation. Any pointers to the method that would simplify this?

推荐答案

直接调用pd.DataFrame构造函数:

df = pd.DataFrame(table, columns=headers)
df

   Heading1  Heading2
0         1         2
1         3         4

这篇关于获取列表列表到Pandas DataFrame中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-26 04:05