A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/pandas-dev/pandas/issues/10824 below:

Merge with empty DataFrame raise IndexError · Issue #10824 · pandas-dev/pandas · GitHub

Skip to content Navigation Menu

Saved searches Use saved searches to filter your results more quickly

Sign up You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session. Dismiss alert Additional navigation options

BUG: Merge with empty DataFrame raise IndexError #10824

Description
import numpy as np
import pandas as pd

df1 = pd.DataFrame([], columns=['a', 'b', 'c'])
df2 = pd.DataFrame(np.random.randn(3, 3), columns=['x', 'y', 'z'])

# OK
pd.merge(df1, df2, how='right', left_index=True, right_index=True)
#      a    b    c         x         y         z
#0  NaN  NaN  NaN  0.665359  0.087728 -0.608138
#1  NaN  NaN  NaN -0.730847  0.882151  0.175648
#2  NaN  NaN  NaN  2.370834 -1.347337 -0.478547

pd.merge(df1, df2, how='outer', left_index=True, right_index=True)
#      a    b    c         x         y         z
#0  NaN  NaN  NaN  0.665359  0.087728 -0.608138
#1  NaN  NaN  NaN -0.730847  0.882151  0.175648
#2  NaN  NaN  NaN  2.370834 -1.347337 -0.478547

# NG, this should be the same as above
pd.merge(df1, df2, how='right', left_on='a', right_index=True)
# IndexError: cannot do a non-empty take from an empty axes.

pd.merge(df1, df2, how='outer', left_on='a', right_index=True)
# IndexError: cannot do a non-empty take from an empty axes.

This works if both DataFrame are empty.

df1 = pd.DataFrame([], columns=['a', 'b', 'c'])
df2 = pd.DataFrame([], columns=['x', 'y', 'z'])

pd.merge(df1, df2, how='right', left_on='a', right_index=True)
# Empty DataFrame
# Columns: [a, b, c, x, y, z]
# Index: []

pd.merge(df1, df2, how='outer', left_on='a', right_index=True)
# Empty DataFrame
# Columns: [a, b, c, x, y, z]
# Index: []

You can’t perform that action at this time.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4