Home > database >  DataFrame returns empty after .update()
DataFrame returns empty after .update()

Time:11-05

I am trying to create a new DataFrame which contains a calculation from an original DF. To that purpose, I run a for loop with the calc for each column, but I am still getting the empty original DF and I don't see where is the source of the error. May I ask for some help here?

import yfinance as yf
import pandas as pd

df = yf.download(["YPFD.BA", "GGAL.BA"], period='6mo')
    
df2 = pd.DataFrame()

for i in ["YPFD.BA", "GGAL.BA"]:
    df2.update(df["Volume"][i] * df["Close"][i])

df2

I expected to create a new DF which contains the original index but with the calculation obtained from original DF

CodePudding user response:

I think this is what you are looking to do:

import yfinance as yf
import pandas as pd

df = yf.download(["YPFD.BA", "GGAL.BA"], period='6mo')
    
df2 = pd.DataFrame()

for i in ["YPFD.BA", "GGAL.BA"]:
    df2[i] = df["Volume"][i] * df["Close"][i]

df2
  • Related