【问题标题】:Question from pandas of resample from quantile function来自分位数函数的重采样熊猫的问题
【发布时间】:2022-01-24 23:45:26
【问题描述】:
import pandas as pd
new = pd.read_csv(r'C:\Users\cctsa\PycharmProjects\pythonProject\stock_2409.csv')
new['time'] = pd.to_datetime(new['time'])
new.set_index(new['time'], inplace=True)
print(new)
rule_type = '10T'
period_n = new[['ticket']].resample(rule=rule_type).quantile(0.75)

关于pandas结合“分位数”功能的问题,它只显示这种方法的一个结果,python可以快速编码同时显示分位数(0.25,0.5,0.75)的结果吗? 谢谢帮帮我。

【问题讨论】:

  • 感谢您对我的反馈。这对我很有帮助。

标签: python pandas quantile


【解决方案1】:

如果需要处理数字列,IIUC 使用close:

print (new['close'].dtype)

period_n = new['close'].resample(rule=rule_type).quantile([0.25, 0.5, 0.75])

或者如果需要根据tickets 处理close 列:

period_n = new.groupby('ticket')['close'].resample(rule=rule_type).quantile([0.25, 0.5, 0.75])

【讨论】:

  • [6642 rows x 6 columns] Empty DataFrame Columns: [] Index: [(2021-12-24 09:00:00, 0.25), (2021-12-24 09:00:00 , 0.5), (2021-12-24 09:00:00, 0.75), 它只显示“空数据框”而没有结果......无论如何,谢谢你这么快给我反馈。
  • @Chrisyu50d - 是票数列吗?答案已编辑。
猜你喜欢
  • 2015-11-21
  • 2017-10-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-11-25
  • 1970-01-01
  • 2013-01-22
  • 1970-01-01
相关资源
最近更新 更多