title: How to split a huge text dataset in python?
body: <p>the first part of my Machine learning project is splitting the huge dataset into 3 parts, and then use them as training data sets and test data set. this dataset includes 10milion rows like the following:</p>
  
  <p><a href="https://i.stack.imgur.com/UQWLy.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UQWLy.png" alt="enter image description here"></a></p>
  
  <p>The above picture is the screenshot of my dataset. I don't want to change the order of columns or rows, so the random doesn't work here. As you can see, they are 6 columns that separated by a tab and includes 10milion of rows. I want to split these rows into 3 separate parts, which the first 3333333.333 rows are my dataset1 and then the second 3333333.333 rows are the dataset2 and the rest is the dataset3. so 3 different text files that the order of components(columns) were not changed.
   I am using Spyder3 and I wrote the following codes by your help:</p>
  
  <pre><code>f = open ( 'pr_data.txt' , 'r')  """Reading File"""
  
  l = [ map(float,line.strip().split()) for line in f ]
  
  no_samples = len(l)
  
  data1 = l[0:int(no_samples/3)][:]
  
  data2 = l[int(no_samples/3):int(no_samples*2/3)][:]
  
  data3 = l[int(no_samples*2/3):no_samples][:]
  
  file = open('data1.txt','w')
  for row in data1: 
      file.writelines(["%s\t" % item for item in row]) 
      file.writelines("\n") 
  file.close()
  
  file = open('data2.txt','w')
  for row in data2: 
      file.writelines(["%s\t" % item for item in row]) 
      file.writelines("\n") 
  file.close()
  
  file = open('data3.txt','w')
  for row in data3: 
      file.writelines(["%s\t" % item for item in row]) 
      file.writelines("\n") 
  file.close()
  </code></pre>
  
  <p>by the above code, the 3 text file is created in the same directory, but the problem is: the precision of numbers is changed. for example, 0's and 1's are changed to 0.0 and 1.0. Also, some of them are not in the same column. Please see the screenshot of the first rows of data1, in the following:
  <a href="https://i.stack.imgur.com/spvOq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/spvOq.png" alt="enter image description here"></a></p>
  
  <p>Please let me know how correct my code?</p>