【发布时间】:2018-11-19 05:08:22
【问题描述】:
您能否告诉我,为什么在 pandas (Python) 和 R 中计算分位数时结果不同?
熊猫代码:
print('p_new: {:>5} {:>5} {:>5}'.format(
round(self.pandas_data_frame['pending_new'].quantile(0.50), 2),
round(self.pandas_data_frame['pending_new'].quantile(0.95), 2),
round(self.pandas_data_frame['pending_new'].quantile(0.99), 2),
))
print('new: {:>5} {:>5} {:>5}'.format(
round(self.pandas_data_frame['new'].quantile(0.50), 2),
round(self.pandas_data_frame['new'].quantile(0.95), 2),
round(self.pandas_data_frame['new'].quantile(0.99), 2),
))
结果:
name | .50| .95| .99|
p_new: 2.0 12.0 20.0
new: 52.0 78.0 106.06
R 代码:
dd = read.csv(“stats.csv”)
quantile(dd$pending_new, c(.50, .95, .99))
quantile(dd$new, c(.50, .95, .99))
结果:
> quantile(dd$pending_new, c(.50, .95, .99))
50% 95% 99%
2.0 13.1 34.0
> quantile(dd$new, c(.50, .95, .99))
50% 95% 99%
52.00 81.00 129.26
【问题讨论】:
标签: python r python-3.x pandas