【发布时间】:2020-10-31 13:58:42
【问题描述】:
我是一名初学者,在 Python 中使用 pandas 库。我目前有一个代码可以读取从我的桌面提取的 csv 文件,具体取决于我提供的程序标题:
string = input("Enter a ticker: ")
file = string + (".csv")
file_location = 'M:\\A*************\\r*******\\files\\r************.tar\\tmp\\p*********\\' + file
if config.is_file():
print(file)
print(file_location)
df = pd.read_csv(file_location)
#print(df)
else:
print("Invalid ticker input")
这允许我的用户输入文件名,并使用 Pandas 读取文件。数据框有 2 列(时间戳、users_holding)和大约 17k 行。
我希望我的用户能够输入日期:
date = input("Enter a date (YYYY-MM-DD): ")
并且程序将返回具有相应日期(时间戳)和用户(users_holding)的行。 例如/
enter ticker: TSLA
enter a date (YYYY-MM-DD): 2019-08-23
timestamp users_holding
2019-08-23 15,097
如果有人知道该怎么做,请告诉我!
【问题讨论】:
-
你不需要搜索字符串——你应该使用正确的 pandas.Timestamps
标签: python pandas numpy dataframe date