title: How to create a dataframe from text file having single column
body: <p>This question might have asked by someone else also but as I couldn't able to find solution for my question, so I'm writing here, hope someone could help me.</p>
  
  <h1>Question</h1>
  
  <p>I've text file in that, all column data has been below one another, how to split those data and create a table.</p>
  
  <h1>Example- Students data.</h1>
  
  <p>SlNo</p>
  
  <p>1</p>
  
  <p>2</p>
  
  <p>3</p>
  
  <p>4</p>
  
  <p>Student Name</p>
  
  <p>A</p>
  
  <p>B</p>
  
  <p>C</p>
  
  <p>D</p>
  
  <p>Grade</p>
  
  <p>First</p>
  
  <p>Second</p>
  
  <p>Third</p>
  
  <p>Fourth</p>
  
  <p>Subject</p>
  
  <p>English</p>
  
  <p>Mathematics</p>
  
  <p>Science</p>
  
  <p>Physics</p>
  
  <p>Marks Obtained</p>
  
  <p>50</p>
  
  <p>65</p>
  
  <p>55</p>
  
  <p>70</p>
  
  <p>Percentage</p>
  
  <p>10%</p>
  
  <p>20%</p>
  
  <p>30%</p>
  
  <p>40%</p>
  
  <p>Above is the sample data on single column(like one below another) and in a text file.</p>
  
  <h1>How to create a dataframe from text file and split the columns</h1>
  
  <p>My code as follows but I'm not getting anything</p>
  
  <pre><code>import pandas as pd
  
  def parse_my_file(filename):
    With open ('sample.txt')as f:
        for line in f:
           yield line.strip(). split (' ',1)
  
  
   df=pd.DataFrame(parse_my_file('sample.txt'))
  </code></pre>
  
  <p>Thanks</p>