• Register
0 votes
3k views

Problem :

I have the two DataFrames which I would want to merge. I have referred many documents and also tried to perform many operations but I am not sure what to do now. Please find my two  DataFrames as below:

DataFrame1:
     id      name  type   currency
0  BTTA.S   Apple  Hard      GBp
1  VOOD.S    Soft Soft      GBp

and

DataFrame2:
   id         price
BTTA.S     301.2215250
VOOD.S    213.7914000

and I would like to return:

      id    name    type    currency   price
0  BTTA.S   Apple  Hard      GBp  301.2215250
1  VOOD.S    Soft  Soft      GBp  213.7914000

Trying to merge the price column from the DataFrame2 with DataFrame1.

I have already tried many methods of doing this as below :

Result = DataFrame1.merge(DataFrame2[['*.S']], left_on='id', right_index=True) 

But here I met with the exception as below :

ValueError: can not merge DataFrame with instance of type <class 'pandas.core.series.Series'>
6 5 3
7,540 points

Please log in or register to answer this question.

1 Answer

0 votes

Solution :

 The error message clearly indicates that your DataFrame2 is of the type as pd.Series. You must try to convert your DataFrame2 .to_frame() as the .merge() needs the pd.DataFrame() as the input (please see docs to get clarity):
DataFrame1.merge(DataFrame2[['*.S']].to_frame(), left_on='id', right_index=True)

while you probably also just could do following :

DataFrame1.merge(DataFrame2.to_frame(), left_on='id', right_index=True)

Or you can use the pd.DataFrame.join() which accepts the pd.Series.

I hope this will help in resolving your issue.
9 7 4
38,600 points

Related questions

0 votes
1 answer 20 views
20 views
Problem: HELP! I need help understanding this error: Can not merge dataframe with instance of type <class 'pandas.core.series.series'>.
asked Mar 6 Wafa Abu Yousef 6.1k points
0 votes
1 answer 10 views
10 views
Problem: I am getting this valueerror: can not merge dataframe with instance of type <class 'pandas.core.series.series'>. Kindly Help..!
asked Mar 6 Umar Ahmad 4.1k points
0 votes
1 answer 35 views
35 views
Problems I am trying to update selected datetime64 values in a pandas data frame using the loc method to select rows satisfying a condition. However, instead of assigning the new date-time value it results in NaT. Here is a simplification of my code that shows the problem: ... as the second element in the new_date column. Any ideas on how this should be done or why this is not working as intended?
asked Sep 15, 2020 Marivoke 530 points
0 votes
1 answer 49 views
49 views
Problem : Any clue: Pandas data cast to numpy dtype of object. check input data with np.asarray(data)..
asked Mar 6 Wafa Abu Yousef 6.1k points
0 votes
1 answer 5.7K views
5.7K views
Problem : I have the pandas data frame with some of the categorical predictors or variables as 0 & 1, and some of the numeric variables. When I fit that to a stasmodel like below : est = sm.OLS(y, X).fit() It throws the below error : Pandas data ... hundreds of variables. For that I have concatenated the 3 pandas DataFrames to come up with the final DataFrame to be used in the model building.
asked Dec 18, 2019 alecxe 7.5k points
0 votes
1 answer 59 views
59 views
Problem: attributeerror: 'dataframe' object has no attribute 'sort'
asked Feb 18 charles mathews 5.5k points
0 votes
1 answer 3 views
3 views
Problem: I want to apply my custom function (it uses an if-else ladder) to these six columns (ERI_Hispanic, ERI_AmerInd_AKNatv, ERI_Asian, ERI_Black_Afr.Amer, ERI_HI_PacIsl, ERI_White) in each row of my data frame.
asked Apr 2 ummesalma 25.2k points
0 votes
1 answer 7 views
7 views
Problem: pandas to_csv float_format. help me to get this one.
asked Mar 14 Ethan ross 2.7k points
0 votes
1 answer 22 views
22 views
Problem: I have a big dataframe and I am trying to split that and after concat that but facing following error first argument must be an iterable of pandas objects, you passed an object of type "dataframe"
asked Mar 6 Wafa Abu Yousef 6.1k points