gpt4 book ai didi

python - Pandas 蟒 : how to get values on data frame every 10 steps?

转载 作者:太空宇宙 更新时间:2023-11-04 06:52:12 26 4
gpt4 key购买 nike

我有一个简单的问题。我有以下数据框

df =
time lat lon
0 2014-03-26 14:46:27.457233+00:00 48.7773 11.428897
1 2014-03-26 14:46:28.457570+00:00 48.7773 11.428719
2 2014-03-26 14:46:29.457665+00:00 48.7772 11.428542
3 2014-03-26 14:46:30.457519+00:00 48.7771 11.428368
4 2014-03-26 14:46:31.457855+00:00 48.7770 11.428193
5 2014-03-26 14:46:32.457950+00:00 48.7770 11.428018
6 2014-03-26 14:46:33.457794+00:00 48.7769 11.427842
7 2014-03-26 14:46:34.458131+00:00 48.7768 11.427668
8 2014-03-26 14:46:35.458246+00:00 48.7767 11.427501
9 2014-03-26 14:46:36.458069+00:00 48.7766 11.427350
10 2014-03-26 14:46:37.458416+00:00 48.7766 11.427224
11 2014-03-26 14:46:38.458531+00:00 48.7765 11.427129
12 2014-03-26 14:46:39.458355+00:00 48.7764 11.427062
13 2014-03-26 14:46:40.458702+00:00 48.7764 11.427011
14 2014-03-26 14:46:41.458807+00:00 48.7764 11.426963
15 2014-03-26 14:46:42.458640+00:00 48.7763 11.426918
16 2014-03-26 14:46:43.458977+00:00 48.7763 11.426872
17 2014-03-26 14:46:44.459102+00:00 48.7762 11.426822
18 2014-03-26 14:46:45.458926+00:00 48.7762 11.426766
19 2014-03-26 14:46:46.459262+00:00 48.7761 11.426702
20 2014-03-26 14:46:47.459378+00:00 48.7760 11.426628

我想生成一个新的数据帧 df1,其中包含每 10 个时间步长的值。

df1 =
time lat lon
0 2014-03-26 14:46:27.457233+00:00 48.7773 11.428897
9 2014-03-26 14:46:46.459262+00:00 48.7761 11.426702
19 2014-03-26 14:46:46.459262+00:00 48.7765 11.426787
... ... ... ... ....
len(df) 2014-03-26 14:46:46.459262+00:00 48.7765 11.426787

我试着做类似的事情

df1 = df.iloc[[0:10:len(df)]]

最佳答案

只需使用 iloc 对 df 进行切片并传递一个步骤参数,就可以解释切片行为 here但基本上第三个参数是步长:

In [67]:
df = pd.DataFrame(np.random.randn(100,2))
df.iloc[::10]

Out[67]:
0 1
0 0.552160 -0.910893
10 -2.173707 -0.659227
20 0.811937 0.675416
30 0.533533 0.336104
40 1.093083 -0.943157
50 -0.559221 0.272763
60 -0.011628 1.002561
70 -0.114501 0.457626
80 1.355948 0.236342
90 -0.151979 -0.746238

关于python - Pandas 蟒 : how to get values on data frame every 10 steps?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32725823/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com