Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/331.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_Arrays_Pandas_List_Csv - Fatal编程技术网

Python将累计数量、价格添加到数组中

Python将累计数量、价格添加到数组中,python,arrays,pandas,list,csv,Python,Arrays,Pandas,List,Csv,我在熊猫数据框中有以下格式的交易数据: price, qty, time 123, 100, 9:00 125, 200, 9:05 130, 300, 9:10 125, 300, 10:01 123, 100, 11:05 等等 我正试图算出我一整天以什么价格买了多少股票。 其想法是将数据从我的数据框中提取到一个新的数组中并绘制它。 阵列应如下所示: 123, 200 125, 500 130, 300 我现在可以跳过的时间数据。 最好的方法是什么 my_array = [] for i

我在熊猫数据框中有以下格式的交易数据:

price, qty, time
123, 100, 9:00
125, 200, 9:05
130, 300, 9:10
125, 300, 10:01
123, 100, 11:05
等等

我正试图算出我一整天以什么价格买了多少股票。 其想法是将数据从我的数据框中提取到一个新的数组中并绘制它。 阵列应如下所示:

123, 200
125, 500
130, 300
我现在可以跳过的时间数据。 最好的方法是什么

my_array = []
for item in df:
  if item not in array:
    my_array.append(item[0])
这应该给我的独特价格,我交易。 现在如何将每个价格的累计股票数量添加到数组中

谢谢,
Eric

你的意思是
如果项目不在我的数组中:
。这就是答案。你愿意使用numpy吗?如果是,请参见
np.unique