Pandas Concat increases number of rows

I solved the problem by using hstack

train = pd.DataFrame(np.hstack([real_data,categorial_data]))

The problem is that sometimes when you perform several operations on a single dataframe object, the index persists in the memory. So using df.reset_index() will solve your problem.


While Performing some operations on a dataframe, its dimensions change not the indices, hence we need to perform reset_index operation on the dataframe.

For concatenation you can do like this:

result_df = pd.concat([first_df.reset_index(drop=True), second_df.reset_index(drop=True)], axis=1)