title: How to get the subset of dataframe based on another dataframe in pandas python
body: <p>I just learnt pandas and basically I want to take the some rows of a dataframe based on the ids that are stored in another dataframe. Let me show you the code:</p>
  
  <pre><code>import pandas as pd
  from sklearn.model_selection import train_test_split
  
  f_data="data.tsv"
  all_data = pd.read_csv(f_data,delimiter='\t',encoding='utf-8',header=None)
  x_data = all_data[[0,1,3]]
  y_data = all_data[[2]]
  
  # Split train and test sets
  x_train,x_test,y_train,y_test = train_test_split(x_data,y_data,test_size=0.1)
  </code></pre>
  
  <p>all_data have 12 columns in total. I use 3 of the columns in x_data and 1 of them in y_data. </p>
  
  <p>Once I create <code>x_train</code> and <code>x_test</code>, I would like to write these instances into <code>tsv</code> files but while doing that I want to write all of the 12 columns stored in <code>all_data</code>. To be able to do that, I need to match the instances in <code>x_train</code> and <code>x_test</code> with <code>all_data</code>. How could I do that ? </p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Here how my data looks like:</p>
  
  <p><code>all_data</code></p>
  
  <pre><code>        0                                                  1                              2    3   ...                                                8                      9     10    11
  0       35  Auch in Großbritannien, wo 19 Atomreaktoren in...                       Ausstieg -1.0  ...                                      Sunday Times           Sunday Times   NaN     1
  </code></pre>
  
  <p><code># continues like that</code></p>
  
  <p><code>x_train</code></p>
  
  <pre><code>         0                                                  1    3
  939   2074  Die CSU verlangt von der schwarz-gelben Koalit...  1.0
  </code></pre>
  
  <p>So, what I want to do is to get the rows starting with 939,710,288,854,433 in all_data and write them into a file.</p>