Pandas Merge Error: Int64 and Object Columns - Solutions & Examples
You are trying to merge on int64 and object columns. If you wish to proceed, you should use pd.concat or pd.merge with the appropriate arguments to specify the columns to merge on and the type of merge to perform.
For example, if you have a DataFrame df1 with an int64 column 'id' and a DataFrame df2 with an object column 'id', you could merge them using pd.merge like this:
merged_df = pd.merge(df1, df2, on='id')
This would perform an inner join on the 'id' column, only including rows where the 'id' values match in both DataFrames.
Alternatively, you could concatenate the two DataFrames along the appropriate axis using pd.concat:
concatenated_df = pd.concat([df1, df2], axis=0)
This would stack the rows of df2 below the rows of df1, assuming they have the same column names. Note that this is not a merge operation and may result in duplicate rows if the two DataFrames have overlapping rows.
原文地址: https://www.cveoy.top/t/topic/lPVd 著作权归作者所有。请勿转载和采集!