This is the code:
import requests
import json
url = ('https://api.coingecko.com/api/v3/coins/bitcoin/market_chart/range?vs_currency=usd&from=1609459201&to=1638313199')
get = requests.get(url).text
get = json.loads(get)
print(get)
Output:
{'prices': [[1609545600000, 29352.12679194895], [1609632000000, 32163.824935335215], [1609718400000, 33008.226203489285], [1609804800000, 31515.575966658354], [1609891200000, 34082.20604904424], [1609977600000, 36933.520137309126], [1610064000000, 39547.08408135567], [1610150400000, 40815.96185478254], [1610236800000, 40296.5290038294], [1610323200000, 38397.895985418174], [1610409600000, 35669.90668663349], [1610496000000, 33938.33587810088], [1610582400000, 37456.00772548642], [1610668800000, 39232.74997140346], [1610755200000, 36787.52121668496], [1610841600000, 36254.713079410845], [1610928000000, 35804.263885674685], [1611014400000, 36595.4647692826], [1611100800000, 36104.86385775514], [1611187200000, 35587.489202735545], [1611273600000, 30913.695736053804], [1611360000000, 32957.908782655926], [1611446400000, 32068.08737440817], [1611532800000, 32273.51735032927], [1611619200000, 32375.320062981456], [1611705600000, 32582.10944502123], [1611792000000, 30445.52586511351], [1611878400000, 33128.34752861149], [1611964800000, 34150.81876737221], [1612051200000, 34199.51981036302], [1612137600000, 33064.78676701507], [1612224000000, 33405.99035714327], [1612310400000, 35485.98593382442], [1612396800000, 37494.71762460426], [1612483200000, 36816.50808203406], [1612569600000, 38007.83222908396], [1612656000000, 39279.41286897885], [1612742400000, 38833.34026455532], [1612828800000, 46307.57412159395], [1612915200000, 46569.56483], [1613001600000, 44848.69344950499], [1613088000000, 47815.96175554316], [1613174400000, 47414.1862550079], [1613260800000, 46941.29208582354], [1613347200000, 48607.8745224845], [1613433600000, 47898.487027633135], [1613520000000, 49238.13690672487], [1613606400000, 52143.6788446198], [1613692800000, 51733.075539032034], [1613779200000, 56038.72775892988], [1613865600000, 56377.63347790987], [1613952000000, 57669.3035269179], [1614038400000, 54410.85629451601], [1614124800000, 48691.894831704405], [1614211200000, 49849.378713583144], [1614297600000, 46992.665450048495], [1614384000000, 46551.48747675472], [1614470400000, 46653.52639939581], [1614556800000, 44970.163459946736], [1614643200000, 49787.33995949672], [1614729600000, 48532.23678981703], [1614816000000, 50577.45746915202], [1614902400000, 48727.45120080115], [1614988800000, 49091.81488232977], [1615075200000, 49019.36859236582], [1615161600000, 51313.09262027362], [1615248000000, 52328.5359126325], [1615334400000, 54700.273439277444], [1615420800000, 56020.4877195857], [1615507200000, 57788.86810329514], [1615593600000, 57353.86147197248], [1615680000000, 61315.197932766816], [1615766400000, 59428.967566027764], [1615852800000, 55805.32924923426], [1615939200000, 56830.253335076224], [1616025600000, 59014.92563205099], [1616112000000, 57922.40959262911], [1616198400000, 58243.27060892363], [1616284800000, 58376.15847137206], [1616371200000, 57573.539344778685], [1616457600000, 54370.137557895185], [1616544000000, 54584.86994699455], [1616630400000, 52526.86659704657], [1616716800000, 51416.908304980054], [1616803200000, 55033.100480447036], [1616889600000, 55832.418109618324], [1616976000000, 55728.10132780653], [1617062400000, 57634.92869447539], [1617148800000, 58668.628336761], [1617235200000, 58817.3738884188], [1617321600000, 58801.194843878126], [1617408000000, 59060.02678333801], [1617494400000, 57060.40665471088], [1617580800000, 58228.802623466196], [1617667200000, 58706.81559311396], [1617753600000, 58062.17872433649], [1617840000000, 56134.41738866435], [1617926400000, 58065.644024815316], [1618012800000, 58152.993262141834], [1618099200000, 59979.39281571831], [1618185600000, 59988.02095852983], [1618272000000, 59911.020594847316], [1618358400000, 63576.676041048275], [1618444800000, 62807.12323259299], [1618531200000, 63179.772446084695], [1618617600000, 61497.299569441195], [1618704000000, 60273.86667694734], [1618790400000, 56288.94534001195], [1618876800000, 55721.166052695626], [1618963200000, 56294.728558586925], [1619049600000, 54190.07026283405], [1619136000000, 51965.5664304852], [1619222400000, 51191.1246964079],
I know that we can navigate to price using (get['prices'])
but can we remove the first number of each box ([ ]
)?
A command like "ignore" value before ,
maybe?
The goal output would be:
[29352.12679194895], [32163.824935335215], [33008.226203489285], [31515.575966658354]
This scipt is based on the coingecko API btw.
CodePudding user response:
res = [price[1] for price in get['prices']]
print(res)
output :
>>
[29352.12679194895, 32163.824935335215, 33008.226203489285, 31515.575966658354, 34082.20604904424, 36933.520137309126, 39547.08408135567, 40815.96185478254, 40296.5290038294, 38397.895985418174, 35669.90668663349, 33938.33587810088, 37456.00772548642, 39232.74997140346, 36787.52121668496, 36254.713079410845, 35804.263885674685, 36595.4647692826, 36104.86385775514, 35587.489202735545, 30913.695736053804, 32957.908782655926, 32068.08737440817, 32273.51735032927, 32375.320062981456, 32582.10944502123, 30445.52586511351, 33128.34752861149, 34150.81876737221, 34199.51981036302, 33064.78676701507, 33405.99035714327, 35485.98593382442, 37494.71762460426, 36816.50808203406, 38007.83222908396, 39279.41286897885, 38833.34026455532, 46307.57412159395, 46569.56483, 44848.69344950499, 47815.96175554316, 47414.1862550079, 46941.29208582354, 48607.8745224845, 47898.487027633135, 49238.13690672487, 52143.6788446198, 51733.075539032034, 56038.72775892988, 56377.63347790987, 57669.3035269179, 54410.85629451601, 48691.894831704405, 49849.378713583144, 46992.665450048495, 46551.48747675472, 46653.52639939581, 44970.163459946736, 49787.33995949672, 48532.23678981703, 50577.45746915202, 48727.45120080115, 49091.81488232977, 49019.36859236582, 51313.09262027362, 52328.5359126325, 54700.273439277444, 56020.4877195857, 57788.86810329514, 57353.86147197248, 61315.197932766816, 59428.967566027764, 55805.32924923426, 56830.253335076224, 59014.92563205099, 57922.40959262911, 58243.27060892363, 58376.15847137206, 57573.539344778685, 54370.137557895185, 54584.86994699455, 52526.86659704657, 51416.908304980054, 55033.100480447036, 55832.418109618324, 55728.10132780653, 57634.92869447539, 58668.628336761, 58817.3738884188, 58801.194843878126, 59060.02678333801, 57060.40665471088, 58228.802623466196, 58706.81559311396, 58062.17872433649, 56134.41738866435, 58065.644024815316, 58152.993262141834, 59979.39281571831, 59988.02095852983, 59911.020594847316, 63576.676041048275, 62807.12323259299, 63179.772446084695, 61497.299569441195, 60273.86667694734, 56288.94534001195, 55721.166052695626, 56294.728558586925, 54190.07026283405, 51965.5664304852, 51191.1246964079, 50133.1073963654, 48981.4413932161, 53978.80554728962, 54991.81484262107, 54810.6138506792, 53596.70402266675, 57828.511814425874, 57812.96915967891, 56600.74528738432, 57200.30029871162, 53464.37021950372, 57432.100227087576, 56507.759439869595, 57361.56904328887, 58771.881689509355, 58213.926293744385, 55901.66759456145, 56928.97235660158, 50004.76218313686, 49972.795398372444, 49913.26314398822, 46780.902304688214, 46585.06413538846, 43780.82559782485, 43091.04144756922, 37287.39140242737, 40437.73009625558, 37339.63420134628, 37520.31767547438, 34977.527801962424, 38642.4422973396, 38210.80521759389, 39406.934244116186, 38642.89555434217, 35710.220936529884, 34775.07941347281, 35714.75202018067, 37340.6792659422, 36680.06820180283, 37685.71798174826, 39151.316183800314, 36938.72031139185, 35546.98596483364, 35834.4744744042, 33451.38340714534, 33557.15068309184, 37553.64375851888, 36903.304906778896, 37289.43252210222, 35666.14977877309, 39147.70567879997, 40624.51305316154, 40378.20254971114, 38321.454656574206, 38193.619141943964, 35881.11137137543, 35581.64226773201, 35787.07740523232, 31711.935467727006, 32507.738707026845, 33702.61779371396, 34675.44910530336, 31943.136467863093, 32023.973901774916, 34607.293274083386, 34556.8421269449, 35968.993667970346, 35171.486304850056, 33677.566235922626, 33950.786555181, 34729.89077801021, 35394.213074080915, 33928.13421837147, 34149.98981477412, 33932.25463831538, 32933.578199292395, 33971.297749757956, 33704.53847440508, 34299.938016517444, 33262.6543524462, 32676.38380096018, 32878.50187357147, 31726.038833909817, 31399.653128682126, 31588.6713510167, 31919.393922554555, 30928.211908849244, 29971.903783612062, 32383.78112696872, 32409.499767175417, 33455.55127272261, 34213.59993217662, 35456.124660766836, 37281.91809217662, 39076.59377063225, 40031.19824444798, 39977.75693922764, 41936.261478677225, 41754.16660435275, 39914.82975848789, 39278.766508103676, 38368.35401197897, 39751.58457509862, 40825.381940449704, 42802.13717474142, 44647.57760300116, 43753.217862646314, 46311.00189857689, 45639.51401890709, 45652.06012506926, 44495.20979327958, 47717.27052766495, 47088.85313451467, 47025.00323011282, 46031.75754362583, 44534.454854219905, 45015.46554608543, 46745.03462296988, 49195.87860189616, 48933.689151311635, 49250.54486971799, 49518.57748790696, 47940.6079149608, 49002.70376627545, 47229.070650876114, 49083.10330586219, 48936.537254142204, 48907.27073106221, 47124.25422469402, 47335.42029920565, 48823.05520964915, 49338.78465183332, 49934.5282762881, 50013.02994694588, 51696.206431317885, 52739.800166345514, 46995.16417095979, 46085.02861578186, 46518.94118660236, 44802.60640249699, 45196.488277558245, 46195.21830082935, 45139.83396873267, 47135.43199562694, 48186.53275704722, 47879.47343992101, 47228.65821623257, 48266.62707279063, 47371.03933236471, 42932.94659595412, 40386.62363528928, 43587.22305058473, 44980.898214810935, 42752.1681545072, 42856.855164224515, 43336.861233242744, 42247.355729006355, 41010.37519836549, 41587.66786232295, 43859.32614724109, 48181.87627260008, 47777.762019063, 48282.97113857447, 49260.232321130694, 51668.99422435564, 55415.00574202895, 53894.59599452107, 54010.93747374405, 55125.460337680444, 54711.86959664297, 57572.510855596534, 56335.035460511535, 57487.985880422195, 57452.43178503547, 61809.02394427028, 61165.63564211521, 61583.77443961336, 62017.972725178704, 64517.64856042277, 66237.51755029388, 62541.08693293518, 61029.27093182092, 61572.14043422243, 61173.1663907232, 63228.21382584213, 60604.18888794746, 58641.00147419492, 60767.55585206728, 62283.19805587354, 61837.257002978935, 61471.86846276259, 61121.83120106507, 63247.20896127831, 63130.94235171542, 61601.74357204975, 61247.38494217787, 61661.35866372036, 63153.230193019495, 67617.0155448617, 67145.37493537061, 65061.05440696283, 65005.64515956679, 64432.04794734522, 64660.33535267343, 65648.97779110243, 63933.835442599324, 60448.56251258625, 60603.65586738653, 56987.32233855049, 58459.25551667463, 60082.91166841709, 59139.779279527174, 56386.856853152145, 57748.79317378856, 57198.18384629529, 58897.84698299794, 53827.792865034724, 54533.40388242691, 57237.66113709043, 57848.77353712989]
CodePudding user response:
This code should work for you:
prices = get # Or your dict name here
for i, lst in enumerate(prices["prices"]): # Getting all elements with their index
prices["prices"][i] = [lst[-1]] # Setting List of dict to last element (by their index)
print(prices) # Printing the dict
Output:
{'prices': [[29352.12679194895], [32163.824935335215], [33008.226203489285], [31515.575966658354], ...]}
CodePudding user response:
Since you emphasize that you want to remove:
for a in get['prices']:
del a[0]