Note that there are some explanatory texts on larger screens.

plurals
  1. POCase insensitive pandas.concat
    primarykey
    data
    text
    <p>How would I perform a case insensitive pandas.concat?</p> <pre><code>df1 = pd.DataFrame({"a":[1,2,3]},index=["a","b","c"]) df2 = pd.DataFrame({"b":[1,2,3]},index=["a","b","c"]) df1a = pd.DataFrame({"A":[1,2,3]},index=["A","B","C"]) pd.concat([df1, df2],axis=1) a b a 1 1 b 2 2 c 3 3 </code></pre> <p>but this does not work:</p> <pre><code>pd.concat([df1, df1a],axis=1) a A A NaN 1 B NaN 2 C NaN 3 a 1 NaN b 2 NaN c 3 NaN </code></pre> <p>Is there an easy way to do this?</p> <p>I have the same question for concat on a <code>Series</code>.</p> <p>This works for a <code>DataFrame</code>:</p> <pre><code>pd.DataFrame([11,21,31],index=pd.MultiIndex.from_tuples([("A",x) for x in ["a","B","c"]])).rename(str.lower) </code></pre> <p>but this does not work for a <code>Series</code>: </p> <pre><code>pd.Series([11,21,31],index=pd.MultiIndex.from_tuples([("A",x) for x in ["a","B","c"]])).rename(str.lower) TypeError: descriptor 'lower' requires a 'str' object but received a 'tuple' </code></pre> <p>For renaming, <code>DataFrames</code> use:</p> <pre><code>def rename_axis(self, mapper, axis=1): index = self.axes[axis] if isinstance(index, MultiIndex): new_axis = MultiIndex.from_tuples([tuple(mapper(y) for y in x) for x in index], names=index.names) else: new_axis = Index([mapper(x) for x in index], name=index.name) </code></pre> <p>whereas when renaming <code>Series</code>:</p> <pre><code>result.index = Index([mapper_f(x) for x in self.index], name=self.index.name) </code></pre> <p>so my updated question is how to perform the rename/case insensitive concat with a Series?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload