相关疑难解决方法(0)

在pandas中的数据框中查找非数字行?

我在pandas中有一个大型数据框,除了用作索引的列之外,它应该只有数值:

df = pd.DataFrame({'a': [1, 2, 3, 'bad', 5],
                   'b': [0.1, 0.2, 0.3, 0.4, 0.5],
                   'item': ['a', 'b', 'c', 'd', 'e']})
df = df.set_index('item')
Run Code Online (Sandbox Code Playgroud)

如何找到df其中包含非数字值的数据帧行?

在这个例子中它的第四行中的数据帧,它具有串'bad'a列.如何以编程方式找到这一行?

python dataframe pandas

49
推荐指数
5
解决办法
7万
查看次数

使用resample或groupby - pandas计算时间序列的百分位数/分位数

我有一个小时价值的时间序列,我试图每周/每月得出一些基本的统计数据.

如果我们使用以下抽象数据框,则每列都是时间序列:

rng = pd.date_range('1/1/2016', periods=2400, freq='H')
df = pd.DataFrame(np.random.randn(len(rng), 4), columns=list('ABCD'), index=rng)
Run Code Online (Sandbox Code Playgroud)

print df[:5] 收益:

                            A         B         C         D
2016-01-01 00:00:00  1.521581  0.102335  0.796271  0.317046
2016-01-01 01:00:00 -0.369221 -0.179821 -1.340149 -0.347298
2016-01-01 02:00:00  0.750247  0.698579  0.440716  0.362159
2016-01-01 03:00:00 -0.465073  1.783315  1.165954  0.142973
2016-01-01 04:00:00  1.995332  1.230331 -0.135243  1.189431
Run Code Online (Sandbox Code Playgroud)

我可以打电话:

r = df.resample('W-MON')
Run Code Online (Sandbox Code Playgroud)

然后用:r.min(),r.mean(),r.max(),这些都很好地工作.例如print r.min()[:5]返回:

                   A         B         C         D
2016-01-04 -2.676778 -2.450659 -2.401721 -3.209390
2016-01-11 -2.710066 -2.372032 -2.864887 -2.387026
2016-01-18 -2.984805 …
Run Code Online (Sandbox Code Playgroud)

python group-by resampling quantile pandas

7
推荐指数
1
解决办法
2651
查看次数

标签 统计

pandas ×2

python ×2

dataframe ×1

group-by ×1

quantile ×1

resampling ×1