How to merge two dataframes with different column names but same number of rows?
<p>I have two different data frames in pandas. Example:</p>

<pre><code>df1=a b  df2= c
    0 1       1 
    1 2       2 
    2 3       3 
</code></pre>

<p>I want to merge them so </p>

<pre><code>df1= a b c  
     0 1 1
     1 2 2
     2 3 3
</code></pre>

<p>I tried using <code>df1['c'] = df2['c']</code> but i got a settingwithCopywarnings</p>

<p>In order to merge two dataframes you can use this two examples. Both returns the same goal.</p>

<p>Using <code>merge</code> plus additional arguments instructing it to use the indexes</p>

<p>Try this:</p>

<pre><code>response = pandas.merge(df1, df2, left_index=True, right_index=True)
In [2]: response
Out[2]:
    b   c
0   1   1
1   2   2
2   3   3
</code></pre>

<p>Or you can use <code>join</code>. In case your daraframes are differently-indexed.</p>

<blockquote>
  <p>DataFrame.join is a convenient method for combining the columns of two potentially differently-indexed DataFrames into a single result DataFrame.</p>
</blockquote>

<p>Here is a basic example:</p>

<pre><code>result = df1.join(df2)
In [3]: result
Out[3]:
    b   c
0   1   1
1   2   2
2   3   3
</code></pre>

python pandas dataframe