我有一個OpenOffice calc,裏面有一長數據表,我需要將其中一列中的數字作爲Python中的向量導入,並將相鄰列中的數字作爲另一列導入矢量,以便我可以稍後使用它們進行多項式插值。從兩個OpenOffice Calc列中讀取數據
有沒有簡單的方法來做到這一點?我是一名Python初學者,無法通過在線教程解決我的問題,但似乎不應該太困難。
我有一個OpenOffice calc,裏面有一長數據表,我需要將其中一列中的數字作爲Python中的向量導入,並將相鄰列中的數字作爲另一列導入矢量,以便我可以稍後使用它們進行多項式插值。從兩個OpenOffice Calc列中讀取數據
有沒有簡單的方法來做到這一點?我是一名Python初學者,無法通過在線教程解決我的問題,但似乎不應該太困難。
在過去,我使用python的csv
庫來讀取和處理來自電子表格的數據(您必須將電子表格轉換爲csv)。 Check the manual here,特別是csv.DictReader
。
在示例代碼片段中,只需更改for row in reader:
循環以隨意保存一行。
看看在openpyxl http://openpyxl.readthedocs.io/en/default/tutorial.html
一個可能的解決方案:
from openpyxl import load_workbook
wb = load_workbook(filename='your_file', read_only=True) # change your_file
ws = wb['dump_newssources'] # specify the sheet in the file
for element in ws.iter_rows():
for i, cell in enumerate(element):
if(i == 0): # value in the first cell of the row
pass # do something
elif(i == 1): # value in the second cell of the row
pass # do something