How can I make the for work in this function?

Question:

could you help me with this problem? damned for! :p

def exchange(x):
    r = requests.get(URL1 + x + URL2)
    js = r.json()
    df = pd.DataFrame.from_dict(js, orient="index").transpose()
    return df

if capture data with next code, after individual append() i have expected answer:

c = exchange("tiendacrypto")
d = exchange("belo")
c.append(d)

but, i don’t find the error in the for:

a = []
for i in exchanges:
    print(exchange(i))
    a = exchange(i)
    a.append(a)
Asked By: Tin

||

Answers:

You’re using a twice.

  = []
       :
     ( ( ))
      =  ( ) # Here is overwritten!
     . ( )#
results = []
       :
    df =  ( )
     ( (df))
    results. (df)
Answered By: Daraan

The issue here is the reassignment of the a value on line 2 in the for loop.

You need to use a different variable name.

  = []
       :
     ( ( ))
    x =  ( )
     . (x)

Notice how we dont now change a in each loop.

Answered By: Karrot96
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.