Home > Net >  Converting a dictionary to DataFrame in python for stocks - ValueError: If using all scalar values,
Converting a dictionary to DataFrame in python for stocks - ValueError: If using all scalar values,

Time:02-01

Need to convert a dictionary to DataFrame in python. My current attempt and error

I understand I cannot use Scalar values but the dictionary is getting picked up directly from Yahoo finance API and I need all of that data to be put into a DataFrame but if I do a direct Signal_data = pd.DataFrame - it skips the Stock name which is important.

Is there any way to directly convert the entire signal_data into a DataFrame including the Stock Name which is UPL.NS and INFY.NS and the date.

CodePudding user response:

Are you using the yfinance package? If so there is detailed discussion in the following thread on how to correctly read in multiple stocks:

How to deal with multi-level column names downloaded with yfinance

CodePudding user response:

The error of the code you posted is about the index=[0] argument you pass when you construct the DataFrame.

From the official pandas documentation site, for creating a DataFrame from a Python dict, there is no index argument in the DataFrame construction. Try to create the DataFrame according to the Pandas site, and report any problems with a code sample.

Regards

  •  Tags:  
  • Related