. Advertisement .
..3..
. Advertisement .
..4..
Hello everyone, urgent situation!!!! I have 2 dataframes and I want to merge them together. However I have a trouble with the error “can not merge dataframe with instance of type <class ‘pandas.core.series.series’>”. My 2 dataframes look like this:
df1:
id name type currency
0 BTA.S Applewood Hard GBp
1 VOD.S Softwood Soft GBp
df2:
id
BTA.S 301.221525
VOD.S 213.791400
This is the program I want to run:
id name type currency price
0 BTA.S Applewood Hard GBp 301.221525
1 VOD.S Softwood Soft GBp 213.791400
However when I execute this method:
Result = df1.merge(df2[['*.S']], left_on='id', right_index=True)
I immediately received the following error message:
ValueError: can not merge DataFrame with instance of type <class 'pandas.core.series.Series'>
and when I’m running this:
Result = pd.concat([Df1, Df2], axis=1, ignore_index=True)
I received the following error message:
ValueError: labels ['type'] not contained in axis
I looked over the documentation and attempted to conduct the following procedure, but I’m not sure how to do it. Please help me find a way to fix this! Thank you very much !!!!
The cause:
After studying your post I realized this is an error because you are leaving
df2
of typepd.Series
.Solution:
You must change
df2
.to_frame()
as.merge()
needs apd.DataFrame()
input.There are 3 ways for you to fix this error:
Or you can fix the error by this:
The last way is using
pd.DataFrame.join()
that allows apd.Series
. Hope my suggestions will help you. Good luck!!!