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

Python 收集每天的所有交易记录,并报告当天的总花费

Python 收集每天的所有交易记录,并报告当天的总花费,python,date,sum,Python,Date,Sum,我有一个像这样的数据框 date Burned 8/11/2019 7:00 0.0 8/11/2019 7:00 10101.0 8/11/2019 8:16 5.2 我有以下代码: import pandas as pd import numpy as np # Read data from file 'filename.csv' # (in the same directory that your python process is based) # Control de

我有一个像这样的数据框

date    Burned
8/11/2019 7:00  0.0
8/11/2019 7:00  10101.0
8/11/2019 8:16  5.2
我有以下代码:

import pandas as pd 
import numpy as np
# Read data from file 'filename.csv' 
# (in the same directory that your python process is based)
# Control delimiters, rows, column names with read_csv (see later) 
df = pd.read_csv("../example.csv") 
# Preview the first 5 lines of the loaded data 



df = df.assign(Burned = df['Quantity'])
df.loc[df['To'] != '0x0000000000000000000000000000000000000000', 'Burned'] = 0.0
# OR:

df['cum_sum'] = df['Burned'].cumsum()
df['percent_burned'] = df['cum_sum']/df['Quantity'].max()*100.0

a=pd.concat([df['DateTime'], df['Burned']], axis=1, keys=['date', 'Burned'])

b=a.groupby(df.index.date).count()
但是我得到了这个错误:
AttributeError:'RangeIndex'对象没有属性'date'


基本上,我想按天对所有这些时间进行排序,因为它一整天都有时间戳。我不在乎一天中什么时候发生了不同的事情,我只想得到每天“烧掉”的总数。

首先添加
parse_dates=['DateTime']
转换列
DateTime

df = pd.read_csv("../example.csv", parse_dates=['DateTime']) 
或第一列:

df = pd.read_csv("../example.csv", parse_dates=[0]) 
在您的解决方案中是
日期
列,因此需要使用
总和

b = a.groupby(a['date'].dt.date)['Burned'].sum().reset_index(name='Total')

我得到这个错误:AttributeError:只能使用带有datetimelike值的.dt访问器为什么它说它不是datetime?有没有办法让它成为datetime?@Jackson-使用
df=pd.read\u csv(“../example.csv”,parse\u dates=['datetime'])
这给了我当天的交易总数。如何获取与这些事务对应的已刻录列中的总数?@Jackson-然后使用
a.groupby(a['date'].dt.date)['Burned'].sum().reset_index(name='total')
我得到了无效的语法