Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 正在尝试从输入提示将日期传递到搜索_Python 3.x_Pandas - Fatal编程技术网

Python 3.x 正在尝试从输入提示将日期传递到搜索

Python 3.x 正在尝试从输入提示将日期传递到搜索,python-3.x,pandas,Python 3.x,Pandas,我试图弄清楚如何将用户提示输入的日期传递给pandas,以便按日期进行搜索。我让搜索和输入提示符分别工作,但不能同时工作。我会告诉你我的意思。也许有人可以告诉我如何正确地将日期传递给熊猫进行搜索 这就是我如何在列emr_first_access_date中的任何单元格大于或等于“2019-09-08”时成功使用pandas提取excel工作表中的行的方法 我使用以下代码成功地完成了此操作: import pandas as pd HISorigFile = "C:\\folder\\inputf

我试图弄清楚如何将用户提示输入的日期传递给pandas,以便按日期进行搜索。我让搜索和输入提示符分别工作,但不能同时工作。我会告诉你我的意思。也许有人可以告诉我如何正确地将日期传递给熊猫进行搜索

这就是我如何在列emr_first_access_date中的任何单元格大于或等于“2019-09-08”时成功使用pandas提取excel工作表中的行的方法

我使用以下代码成功地完成了此操作:

import pandas as pd
HISorigFile = "C:\\folder\\inputfile1.xlsx"
#opens excel worksheet
df = pd.read_excel(HISorigFile, sheet_name='Non Live', skiprows=8)
#locates the columns I want to write to file including  date column emr_first_access_date if greater than or equal to '2019-09-08'
data = df.loc[df['emr_first_access_date'] >= '2019-09-08', ['site_name','subs_num','emr_id', 'emr_first_access_date']]
#sorts the data
datasort = data.sort_values("emr_first_access_date",ascending=False)
#this creates the file (data already sorted) in panda with date and time. 
datasort.to_excel(r'C:\\folder\sitesTestedInLastWeek.xlsx', index=False, header=True)
然而,上面的日期当然是硬编码的。因此,我需要运行此脚本的用户输入日期。我用以下内容创建了一个非常基本的工作输入提示符:

import datetime
#prompts for input date
TestedDateBegin = input('Enter beginning date to search for sites tested in YYYY-MM-DD format')
year, month, day = map(int, TestedDateBegin.split('-'))
date1 = datetime.date(year, month, day)
显然,我想将TestedAtebegin传递给pandas,更改相关的代码行:

data = df.loc[df['emr_first_access_date'] >= '2019-09-08', ['site_name','subs_num','emr_id', 'emr_first_access_date']]
例如:

data = df.loc[df[b]['emr_first_access_date'] >= 'TestedDateBegin', ['site_name','subs_num','emr_id', 'emr_first_access_date']]
显然这不起作用。但我该怎么做呢?我对编程非常陌生,所以我并不总是清楚如何继续。是否需要将TestedAtebegin中输入的日期添加到报税表中?还是应该把它放在一个单一的项目清单中?什么是正确的方法?谢谢

这已解决

我不得不删除testedatebegin周围的单引号,因为python当然将其解释为字符串而不是变量。生活和学习。:-)

data = df.loc[df[b]['emr_first_access_date'] >= TestedDateBegin,['site_name','subs_num','emr_id', 'emr_first_access_date']]