1

I have a dynamic plot, in which I'm receiving remote data. I'm now gathering some latencies to a txt file, and I'm updating the mean latency every time new data comes in. My function who does this is:

def calc_latenc():

    global average

    lista = []

    with open('latenciaEdge.txt', 'r') as file:
        last10 = deque(file, 10)

    for item in last10:
        lista.append(item.rstrip())

    average = pd.Series(pd.to_timedelta(lista).mean())

The displaying in my figure comes from:

calc_latenc()
ax1.set_xlabel('Latência Média : {} segundos'.format(average), fontsize = 9)

The output comes in this form:

0   00:00:49.460746
dtype: timedelta64[ns]

and I can't seem to format this as I want. The "dtype.." seems imutable. Not even transforming in to string and try cutting the edges seems to work. The ideia is to display only the "HH:MM:SS".

Thanks in advance!

vaughan is god
  • 162
  • 1
  • 13
  • try adding `.round('s')` to the end of your mean – ALollz Aug 22 '19 at 19:32
  • Hi, ALollz. Thanks for the answer. This crops que miliseconds, but I still get the "dtype: timedelta64[ns]" nonetheless. :( – vaughan is god Aug 22 '19 at 19:34
  • 2
    Then don't use a Series; there seems to be no reason for that at all. `average = pd.to_timedelta(lista).mean().round('s')` – ALollz Aug 22 '19 at 19:36
  • Series was my 'go to' since I needed to grab the mean from datetimes. Didn't even think about doing without it. This resolves my problem. Thanks a lot, ALollz! – vaughan is god Aug 22 '19 at 19:38
  • 1
    No problem. If you ever have a Series and you need to print it, without the indices or dtype you can see: https://stackoverflow.com/questions/29645153/remove-name-dtype-from-pandas-output. In this case `average.to_string(index=False)`, but again just ditch the Series. – ALollz Aug 22 '19 at 19:39
  • Just ditched it hehehe kindof overkill, I see it now. Thanks again. Very informative :) – vaughan is god Aug 22 '19 at 19:46

0 Answers0