Save the number of rows of a dataframe to a variable

Asked

Viewed 17 times

-1

I have a dataframe that is generated randomly by varying its number of lines. I would like to save this variable number for future use.

Follow the example of dataframe:

inserir a descrição da imagem aqui

And I’d like to replace the number of lines with that 10 to make it more automated.

i = 0
lista = []

while i < 10:
  lin = x.loc[i]['index']
  p = yf.Ticker(lin)
  lista.append(p.info)
  lista.append("-----------------------")
  i = i + 1

1 answer

0


If I understand correctly you want to replace that 10 fixed by the number of lines that were generated randomly in its dataframe, that’s it?

In this case you can use the method shape which shows the amount of lines and columns of a dataframe. You can even do the following to have each of these values stored in a variable:

linhas, colunas = dataframe.shape

then just use this info for what you want, in your case:

i = 0
lista = []

while i < linhas:
  lin = x.loc[i]['index']
  p = yf.Ticker(lin)
  lista.append(p.info)
  lista.append("-----------------------")
  i = i + 1

Browser other questions tagged

You are not signed in. Login or sign up in order to post.