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

问题描述

我正在将电子表格的内容读入 Pandas.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:04