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)
Answers:
You’re using a
twice.
= []
:
( ( ))
= ( ) # Here is overwritten!
. ( )#
results = []
:
df = ( )
( (df))
results. (df)
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.
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)
You’re using a
twice.
= []
:
( ( ))
= ( ) # Here is overwritten!
. ( )#
results = []
:
df = ( )
( (df))
results. (df)
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.