1

I'm concatenating two pandas DataFrames column-wise (axis=1), with join='inner' like so:

import pandas as pd

print('pd.__version__ = ', pd.__version__)

DF_empty = pd.DataFrame()
DF_a = pd.DataFrame({'a': [1, 2]}, index=[0, 1])
DF_b = pd.DataFrame({'b': [3]}, index=[1])

DF_empty_inner_a = pd.concat([DF_empty, DF_a], axis=1, join='inner')
DF_a_inner_b = pd.concat([DF_a, DF_b], axis=1, join='inner')

print('empty inner a:\n{}\n'.format(DF_empty_inner_a))
print('a inner b:\n{}'.format(DF_a_inner_b))

and I get:

pd.__version__ = 0.19.2

empty inner a:
   a
0  1
1  2

a inner b:
   a  b
1  2  3

but I was expecting that DF_empty_inner_a would be empty.

Is this a bug, a feature, or my misconception?

4
  • In my opinion it is bug. merge alternative works nice print (pd.merge(DF_empty, DF_a, left_index=True, right_index=True)) Commented Feb 7, 2017 at 7:46
  • 1
    I report it here Commented Feb 7, 2017 at 7:56
  • I think as you have not mentioned the Index value, pandas wouldn't consider the empty dataframe. However, if you mention the index value while creating the empty dataframe, the result will produce like this: Empty DataFrame Columns: [] Commented Feb 7, 2017 at 8:07
  • @Chandan, I get Empty DataFrame Columns: [] Index: [] either way (for DF_empty = pd.DataFrame(), and for DF_empty = pd.DataFrame(index=[])). Commented Feb 7, 2017 at 9:13

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.