Home > Blockchain >  How do I take the mean of this output
How do I take the mean of this output

Time:11-23

I have this function

updated the code a bit

for c,d,y in zip(crypto.Wicker,crypto.Dateroundts,crypto.Dateround1ts):
        yst = cg.get_coin_market_chart_range_by_id(c,'usd', d, y)
        print(c)
        #yst = {k: [[np.nan, np.nan]] if not v else v for k, v in yst.items() }
        bst = list(yst.values())[0]
        caz = []
        for new_lst in bst:
            caz.append(new_lst[1])
            print(caz)

buu-inu
[1.7844348972932573e-05]
[1.7844348972932573e-05, 1.8661555226871793e-05]
[1.7844348972932573e-05, 1.8661555226871793e-05, 1.879232323095649e-05]
[1.7844348972932573e-05, 1.8661555226871793e-05, 1.879232323095649e-05, 1.8801994944205594e-05]

What I want is to take all the prices for the individual coin and take the mean. Then put said mean into the list. If I do something like mean(new_lst[1]) I'll get an error float object is not iterable

heres what print(bst) outputs

buu-inu
[[1637557978123, 1.7844348972932573e-05], [1637559018888, 1.8661555226871793e-05], [1637560001812, 1.879232323095649e-05], [1637560315539, 1.8801994944205594e-05]]

The first number is the time in unix and the second input is the price

CodePudding user response:

Given this value of bst:

>>> bst = [[1637557978123, 1.7844348972932573e-05], [1637559018888, 1.8661555226871793e-05], [1637560001812, 1.879232323095649e-05], [1637560315539, 1.8801994944205594e-05]]

you can unpack each sublist into time and price and take the mean of the prices:

>>> from statistics import mean
>>> mean(price for [_, price] in bst)
1.8525055593741612e-05
  • Related