Search code examples
pythonpandasjoinconcatenationright-join

Can't concatenate pandas dataframes with the same length?


This is weird. From the documentation I all ready read how to do concat and merge operations with pandas. Also I all ready know that concatenating to the right side can be done as follows:

df = pd.concat([df1, df2], axis=1)

The issue is that I generated the following dataframes:

In:

links = pd.DataFrame(links, columns=['link'])

So, I just want to concatenate the link dataframe column to intersection dataframe (note that link and intersection have 78 instances of length). Thus:

In:

full_table = pd.concat([lis_, lis_2], axis=1)

The problem is that as you can see in the above dataframe, it added some NaN values. Therefore, which is the correct way of concatenating links and intersection dataframes?.


Solution

  • Maybe your indexes don't match up. Try using the ignore_index parameter:

    full_table = pd.concat([intersection, links], axis=1, ignore_index=True)