回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>我有一个CSV作为日志文件/db。其结构如下:</p>
<pre><code>User1,Client3,Ops/Admin,19:33:46,19:33:57,178.054662,Notes,05/09/2018
User1,Client2,Ops/Admin,20:33:46,20:33:57,449.272576,Notes,05/09/2018
User1,Client3,Support Management,21:33:46,21:33:57,1073.425258,Notes,05/09/2018
User1,Client2,Support Management,22:33:46,22:33:57,290.640219,Notes,05/09/2018
User1,Client3,Ops/Admin,23:33:46,23:33:57,402.223927,Notes,05/09/2018
User1,Client1,Support Management,00:33:46,00:33:57,761.266062,Notes,05/09/2018
User1,Client1,Business Developement,01:33:46,01:33:57,1623.303656,Notes,05/09/2018
</code></pre>
<p>我想用matplotlib.pyplot做一个折线图,它将每个客户在每个日期的第[5]列的总和相加。即同一图表上的另一条线,其中x轴是日期(第[7]列),y轴是该日期值的总和(第[5]列)</p>
<p>我使用熊猫,这是我的出发点:</p>
<pre><code>import matplotlib.pyplot as plt
import pandas as pd
import datetime, csv
csv_file = pd.read_csv("file.csv",
names = ['USER',
'CLIENT',
'TYPE',
'START',
'END',
'DURATION',
'NOTES',
'DATE'])
</code></pre>
<p>然后,我尝试将表作为透视表:</p>
<pre><code>date_pivot = csv_file.pivot_table('DURATION', index='CLIENT', columns='DATE')
</code></pre>
<p>或者使用.groupby()函数:</p>
<pre><code>dategroup = csv_file.groupby(['CLIENT','DATE'], as_index = False).sum()
</code></pre>
<p>这两种方法似乎都生成了一个表,看起来应该足够使用它了</p>
<p>问题是,由于不乏尝试(…),我无法在matplotlib.pyplot.plot()上按日期绘制客户机的求和值。。。你能帮忙吗</p>
<p>到目前为止,我唯一的想法是:</p>
<ul>
<li>不知何故,我应该重新排列表,让客户机沿着Y轴(/索引)运行,而日期沿着x轴(/标题)运行吗</李>
<li>它是否需要使用.loc()的某种形式的def迭代函数</李>
</ul>
<p>在此方面的任何帮助都将不胜感激,因此提前感谢</p>