我有如下数据帧:
d = {'item': [1, 2,3,4,5,6], 'time': [1297468800, 1297468809, 12974688010, 1297468890, 1297468820,1297468805]}
df = pd.DataFrame(data=d)
df
的输出如下:
item time
0 1 1297468800
1 2 1297468809
2 3 1297468801
3 4 1297468890
4 5 1297468820
5 6 1297468805
这里的time
基于unixsystem时间。我的目标是替换数据帧中的time
列。你知道吗
例如
mintime = 1297468800
maxtime = 1297468890
我想把时间分割成10
(可以通过使用类似于20个区间的参数来更改)区间,并重新编码df
中的time
列。例如
item time
0 1 1
1 2 1
2 3 1
3 4 9
4 5 3
5 6 1
既然我有上亿张唱片,那么最有效的方法是什么?谢谢
您可以使用
pd.cut
和np.linspace
来指定箱子。这将对列进行分类编码,然后可以从中按顺序提取代码:或者,根据处理间隔边的方式,也可以这样做
相关问题 更多 >
编程相关推荐