python - 如何在 pd.Excel() 数据框中使用 pandas python 在特定行中附加列?
问题描述
这是我必须找到并阅读特定行的内容:
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()
上面的代码返回当前日期的行,我需要获取该特定行并为其编辑列。
解决方案
推荐阅读
- python-3.x - 如何以不同的方式将python脚本的输出保存在文本文件中
- r - ggplot2中geom_point的npc坐标
- elasticsearch - 无法访问 Pinterest 搜索结果
- c# - c#表单上的标签不反映文本更改
- c# - 身份验证操作不起作用重定向不起作用
- excel - 如何将列中的两种日期格式更改为excel中的一种?
- powershell - 我可以在不覆盖“keys”成员的情况下将名为“keys”的键添加到哈希表吗
- python-3.x - 如何在 iframe 中获取嵌入谷歌地图的信息?
- tensorflow - Tensorflow.keras 错误使用 Conv2D 输入深度和过滤器深度不兼容?
- python - 无法在python中安装硒