1

I can't seem to figure out how to build a dataframe from a series of new dataframes which all have the same index ( date ). I have the creation of the destination dataframe working properly BUT it's the changing of the index from 0...n to the dates that has me stumped.

I am building a dataframe df_new_sym

and adding it as a column to another dataframe

df_all_sym

this will continue for as many new columns are needed.

**df_new_sym** date iv_close_abs 0 2020-03-11 7.695 1 2020-03-12 22.172 2 2020-03-13 -8.108 3 2020-03-16 26.308 

will CURRENTLY result in

**df_all_sym** type_a type_b 0 7.695 10.00 1 22.172 11.23 2 -8.108 14.78 3 26.308 9.98 

I want the index of df_all_sym to be the date range coming from df_new_sym.

 date type_a type_b 2020-03-11 7.695 10.00 2020-03-12 22.172 11.23 2020-03-13 -8.108 14.78 2020-03-16 26.308 9.98 
3
  • Please show your code, because I cannot guess what you did... Commented Apr 28, 2020 at 14:44
  • sorry I forgot to add the relevant code Commented Apr 28, 2020 at 14:53
  • I had to remove the code as it was confusing people. I have the df_all_sym building correctly it's the INDEX problem that has me stumped Commented Apr 28, 2020 at 16:55

1 Answer 1

3

just try the below code. It may solve the issue

df_all_sym = pd.merge(df_new_sym,df_all_sym,left_on='iv_close_abs',right_on='type_a',how='left') 

followed by

df_all_sym = df_all_sym.set_index('date')

Sign up to request clarification or add additional context in comments.

2 Comments

Sorry I wasn't clear what the problem is. I can create the df_all_sym columns from the df_new_sym and that works fine. What is NOT happening is that the INDEX of df_all_sym should be the index of df_all_sym. I had tried setting the set_index approach but it doesn't work.
I changed the question to "hopefully" clarify the problem. It's the INDEX not the df_all_sym creation that's the issue.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.