连接excel数据与python或Excel

这是我的问题,我有一个Excel工作表2列(见下文) 在这里输入图像说明

我想打印(在Python的控制台或在Excel单元格)在这种forms下的所有数据:

"1" : ["1123","1165", "1143", "1091", "n"], *** n ∈ [A2; A205]*** 

我们并不关心B列,但是我需要在这个特定的表格下添加每个邮政编码。

有没有办法用Excel或Python与pandas? (如果你有任何其他的想法,我很乐意听到他们)

干杯

我认为你可以使用parse_colsparsing第一列,然后通过skiprows中的read_excel过滤出从205到1000的所有列:

 df = pd.read_excel('test.xls', sheet_name='Sheet1', parse_cols=0, skiprows=list(range(205,1000))) print (df) 

最后使用tolist将第一列转换为list

 print({"1": df.iloc[:,0].tolist()}) 

最简单的解决scheme是只parsing第一列,然后使用iloc

 df = pd.read_excel('test.xls', parse_cols=0) print({"1": df.iloc[:206,0].astype(str).tolist()}) 

我对excel不熟悉,但pandas可以轻松解决这个问题。

首先,读取一个DataFrame的Excel

 import pandas as pd df = pd.read_excel(filename) 

然后,打印,只要你喜欢

 print({"1": list(df.iloc[0:N]['A'])}) 

其中N是您想要打印的数量。 这就对了。 如果列表不是string列表,则需要将int转换为string。

另外,有很多参数可以控制excel read_excel的加载部分,你可以通过文件来设置合适的参数。

希望这会对你有所帮助。