title: How to join two or more DataFrames in pandas, python
body: <p>I've trying to join 3 dataframes, however I'm having problems to do it.  Let me show the scenario.</p>
  
  <p>I have 3 dataframes:</p>
  
  <p>First: <strong>Country</strong></p>
  
  <p>just two columns: <strong>Country_ID, Country_Name</strong>
  Primary Key: <strong>Country_ID</strong> </p>
  
  <p><strong>Country_ID</strong> | <strong>Country_Name</strong></p>
  
  <pre><code>BR     |   Brazil
  </code></pre>
  
  <p>Second: <strong>Sports</strong></p>
  
  <p>just three columns: <strong>Country ID, Sport_ID, Sport_Name</strong>
  Primary Key: <strong>Country_ID, Sport_ID</strong></p>
  
  <p><strong>Country_ID</strong> | <strong>Sport_ID</strong>| <strong>Sport_Name</strong></p>
  
  <pre><code>BR         |    1234     |     Football
  </code></pre>
  
  <p>Third: <strong>University</strong></p>
  
  <p>just four columns: <strong>Country_ID, University_ID, University_Name</strong>
  Primary Key: <strong>Country_ID, University_ID</strong></p>
  
  <p><strong>Country_ID</strong> | <strong>University_ID</strong>| <strong>University_Name</strong></p>
  
  <pre><code>BR         |    UFCABC        | Federal University of ABC
  </code></pre>
  
  <p>Final Result: just these columns: <strong>Country_Name, Sport_Name, University_Name</strong></p>
  
  <p><strong>Country_Name</strong> | <strong>Sport_Name</strong> | <strong>University_Name</strong></p>
  
  <p>Brazil     |  Football  |  Federal university of Brazil</p>
  
  <p>I tried to join ContryXSport and after that with university DataFrame, however I wasn't able to do it.</p>
  
  <p>Here is the code for creation and join the dataframes:</p>
  
  <pre><code>country_raw_data = {
              'country_id': [country.id for country in countries],
              'country_name': [country.name for country in countries]                                  }
  
  sport_raw_data = {
              'country_id': [sport.country.id for sport in sports],                
              'sport_id': [sport.id for sport in sports],
              'sport_name': [sport.name for sport in sports]
          }
  
  university_raw_data = {
              'country_id': [university.country.id for university in universities],                
              'university_id': [university.state.id for university in universities],
              'university_name': [university.name for university in universities]
          }
  </code></pre>
  
  <p>Now, the dataframe instances:</p>
  
  <p>I tried to create df like this:</p>
  
  <pre><code>country_df = pd.DataFrame(country_raw_data, columns: ['country_id', 'country_name'])
  </code></pre>
  
  <p>I don't know why, the country_df was create wrong, some columns didn't appear correct with the right values. Then I had to create like this, it is working.</p>
  
  <pre><code>country_df = pd.DataFrame(country_raw_data) 
  sport_df = pd.DataFrame(sport_raw_data) 
  university_df = pd.DataFrame(university_raw_data) 
  </code></pre>
  
  <p>Here, is the joins declarations:</p>
  
  <p>I tried to do like this, however the result didn't join correct. Some columns didn't include the data frame correctly.</p>
  
  <pre><code>country_state_df = pd.merge(country_df, state_df, on='country_id', how='inner')
  </code></pre>
  
  <p>Another code tht I did it, however I had the same problem before:</p>
  
  <pre><code>country_sport_df = pd.merge(country_df, sport_df, 
                          left_on='country_id', 
                          right_on='sport_id', 
                          how='inner')
  </code></pre>
  
  <p>So, after the first join, I did the next join between country_state with city</p>
  
  <pre><code>country_sport_university.df = pd.merge(country_sport_df, university_df, 
                               on=['country_id', 'country_id'], 
                               how='inner')
  </code></pre>
  
  <p>I'd like the final result must be like these columns:</p>
  
  <p><strong>country_name</strong> | <strong>Sport_Name</strong> | <strong>University_Name</strong></p>
  
  <p>Brazil     | Football   | Federal University of ABC</p>
  
  <p>it is possible to do it using dataframe, or I need to use another libraries?</p>
  
  <p>So, there are a lot of data, around millions of data, for example.</p>
  
  <p>Can anyone help my or give me a suggestion to solve the problem?</p>
  
  <p>Thank you very much!</p>