python - 我如何从 pandas.core.frame.DataFrame 中选择特定变量?
问题描述
我希望在这些 DataFrames 中选择一个特定的日期。我只想选择日期2021-09-03
(并查看 adj 关闭和信号)我该怎么做?而且我不想看到没有我想要的日期的 DataFrame。
我试图在这段代码中看到这一点,而为我们提供代码的 DataFrame 是代码df.buyingSignals()
下方的 2 个表:
acciones=['FCEL','CAT']
for accion in acciones:
accion=Ticker(accion, "2021-1-1", "2021-9-20", [5, 10, 20])
accion.buyingSignals()
#np.where(accion.loc['2021-9-03'],accion.buyingSignals(),0) #Possible answer that i think but it's not working
[*********************100%***********************] 1 of 1 completed
********** FCEL **********
Adj Close Signal
Date
2021-02-02 21.430000 1
2021-02-09 27.959999 1
2021-06-02 10.430000 1
2021-08-31 6.240000 1
[*********************100%***********************] 1 of 1 completed
********** CAT **********
Adj Close Signal
Date
2021-02-19 207.849991 1
2021-03-11 217.603302 1
2021-04-01 230.455948 1
2021-04-20 225.396088 1
2021-05-04 232.164093 1
2021-05-10 241.314987 1
2021-05-17 243.483337 1
2021-05-19 235.605621 1
2021-06-09 233.397476 1
2021-07-15 210.281525 1
2021-08-13 218.570007 1
2021-08-31 210.869995 1
2021-09-03 210.369995 1
解决方案
只需使用loc
:
>>> df.loc['2021-09-03']
Adj Close 210.369995
Signal 1.000000
Name: 2021-09-03, dtype: float64
>>>
推荐阅读
- sql-server - 如何在同时调用多次的存储过程中读取更新的数据
- excel - Excel - 希望使用 VBA 来构建包含复制额外单元格的目录
- java - 如何获取具有父 DataLakeDirectoryClient 类实例的子文件/目录列表
- java - “java.lang.NullPointerException:无法调用“java.sql.Connection.prepareStatement(String)”,因为“this.con”为空”
- c# - 为什么分配异步等待事件处理程序不会导致任何问题?
- python - pytest 参数化一个自动使用的夹具
- swift - 准则 2.1 - 性能 - 空白无响应屏幕
- java - 使用 FileProvider 共享下载文件夹中的音频文件
- f# - 使用部分应用程序在 F# 中订阅 c# 事件
- powershell - 将excel变量读入power shell并输出