Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/performance/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何更快地创建熊猫索引?_Python_Performance_Pandas - Fatal编程技术网

Python 如何更快地创建熊猫索引?

Python 如何更快地创建熊猫索引?,python,performance,pandas,Python,Performance,Pandas,为什么以下代码段执行得如此糟糕: 进口numpy 进口大熊猫 time=numpy.arrayrange0,1000000,10,dtype=numpy.uint32 索引=[pandas.Timedeltastrt+'ms'表示时间为t] 在一个像样的桌面上大约需要一秒半的时间,而我们所说的只有一百万只熊猫。Timedelta。有没有关于如何重写最后一行的想法?如果需要,可以使用或: 或: 如果需要,可使用或: 或: 你也可以使用 你也可以使用 pd.to_timedeltatime,unit

为什么以下代码段执行得如此糟糕:

进口numpy 进口大熊猫 time=numpy.arrayrange0,1000000,10,dtype=numpy.uint32 索引=[pandas.Timedeltastrt+'ms'表示时间为t] 在一个像样的桌面上大约需要一秒半的时间,而我们所说的只有一百万只熊猫。Timedelta。有没有关于如何重写最后一行的想法?

如果需要,可以使用或:

或:

如果需要,可使用或:

或:

你也可以使用

你也可以使用


pd.to_timedeltatime,unit='ms'如何?pd.to_timedeltatime,unit='ms'如何?这将性能提高5倍。你是对的。我应该使用TimeDeltaIndex而不是'TimeDelta'数组。谢谢我将在10分钟内接受答案。这将使性能提高5倍。你是对的。我应该使用TimeDeltaIndex而不是'TimeDelta'数组。谢谢我会在10分钟内接受答案。
index = pd.to_timedelta(time, unit='ms')
index = pd.TimedeltaIndex(time, unit='ms')
index = pd.timedelta_range(0, periods=10000, freq='10ms')