这是我必须找到并读取特定行的地方:
from __future__ import print_function
import pandas as pd
import datetime
file = input("name of file: ")
file1 = str(file) +'.xlsx'
xl = pd.ExcelFile(file1)
print (xl.sheet_names)
time = datetime.datetime.time(datetime.datetime.now())
t = time.strftime("%H:%M")
date = datetime.date.today()
d = date.strftime("%m-%d-%y")
def print_excel():
inp = input("name: ")
if inp in str(xl.sheet_names):
print ("true")
matching = [s for s in xl.sheet_names if inp in s]
m = str(matching).strip("'[]")
df = pd.ExcelFile.parse(xl, sheet_name=m, inplace=True,usecols="A,G:L")
with pd.option_context('display.max_rows', 300, 'display.max_columns', 0, 'display.expand_frame_repr', False):
k = df.keys()[0]
print(df[(df[str(k)] == date)])
else:
print("failed")
return print_excel()
print_excel()
上面的代码返回当前日期的行,我需要获取该特定行并为其编辑列。