[英]How to get the row value and column value(date)together of a cell in excel using python
I have an excel pivot table of format:我有一个格式的 excel 数据透视表:
Names 2/1/2010 3/1/2010 4/1/2010
A 8
B 4 5 7
C 5 3
D 6 6
I need to get the names and date of the cells which are empty.我需要获取空单元格的名称和日期。 How can I do it?
我该怎么做? I want the output as a list:
[A:3/1/2010,4/1/2010]
.我希望输出作为列表:
[A:3/1/2010,4/1/2010]
。
Assuming format is same as above, Check this code snippet, you can use different python module to read excel sheet假设格式和上面一样,检查这个代码片段,你可以使用不同的python模块来读取excel表
import xlrd
def get_list_vals() :
res = []
path="C:/File_PATH.xlsx"
wb=xlrd.open_workbook(path)
sheet=wb.sheet_by_index(0)
# Get rows from 2nd line
for row in range(1, sheet.nrows) :
temp = []
for column in range (sheet.ncols) :
val = sheet.cell_value(row,column)
# get first column values like(A, B, C)
if column == 0:
temp.append(val)
continue
# if not first column, get the date data from row = 1
elif val=="" :
date_val = sheet.cell_value(0,column)
temp.append(date_val)
res.append(temp)
return res
If you want specific format like [A : date1, date2] for thhis instead of temp = [] , you can append to string value如果你想要像 [A : date1, date2] 这样的特定格式而不是 temp = [] ,你可以附加到字符串值
temp = [] -->> temp = "" temp = [] -->> temp = ""
temp.append(val) --> temp += str(val) + ":" temp.append(val) --> temp += str(val) + ":"
temp.append(date_val) -->> temp + str(val) + "," temp.append(date_val) -->> temp + str(val) + ","
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.