Python Copy names from txt file to csv format

0 votes
I have a text file consisting of group name, Age, Education details  I want only to copy names from that text file to excel sheet. In the excel sheet names should come Row by row.

Eg: Let us assume this how my text file looks like.

Group 1 Punith 34 MCA Rahlul 33 BCA Jagadish 35 MCA Azhar 40 BE

Group 2  Ajay 32 BCA Pradeep 30 BCA Venkat 25 MCA Sujith 20 BE

when i run the python code i should get output as (I should GET OUTPUT row by row in excel sheet, Clumn1 should be name, Column 2 should be Age and Column should be Education details)

Punith 34 MCA

Rahul 33 BCA

Jagadish 35 MCA

Azhar. 40 BE

Ajay 32 BCA

Pradeep 30 BCA

Venkat  25 MCA

Sujith 20 BE

Can anyone help me with a python code. I am new to python i need it urgent work.
Jun 6, 2020 in Python by ANAND
• 120 points

1 answer to this question.

0 votes


It depends on your use case. In which format you want to retrieve your dataset. According to your example, you can try something as given below.

import pandas as pd
data = pd.read_csv('data.txt.txt',header=None)
data = data.applymap(lambda x: str(x.replace(' ',',')))
data = data[0].str.split(',',expand=True)
df1 = data.iloc[:,2:5]
df2 = data.iloc[:,5:8]
df3 = data.iloc[:,8:11]
objs = [df1,df2,df3]

You have to create some python code according to your use case.

Hope this will give you some idea.

answered Jun 10, 2020 by MD
• 95,440 points

Related Questions In Python

+1 vote
4 answers

Python: convert txt file to csv format with rows and columns

Python will read data from a text ...READ MORE

answered Dec 14, 2020 in Python by Gitika
• 65,910 points
0 votes
1 answer

How to create LIST from CSV file in Python?

You can use the pandas library for this which ...READ MORE

answered Jul 15, 2019 in Python by Karan
–1 vote
2 answers
+1 vote
0 answers

Sum the values of column matching and not matching from a .txt file and write output to a two different files using Python

Name                                                    value DR_CNDAOFSZAPZP_GPFS_VOL.0 139264 DR_CNDAOFSZAPZP_GPFS_VOL.1 15657 DR_CNDAOFSZAPZP_GPFS_VOL.0 139264 DR_CNDAOFSZAPZP_GPFS_VOL.1 156579 DR_CNDAOFSZAPZP_GPFS_VOL.2 156579 DR_CNDAOFSZAPZP_GPFS_VOL.3 ...READ MORE

Nov 20, 2019 in Python by Sagar
• 130 points
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,131 views
0 votes
1 answer
0 votes
1 answer

How to run a Function in Spyder and check output?

You will see the output of the ...READ MORE

answered May 17, 2019 in Python by Omkar
• 69,230 points
0 votes
1 answer

How to call a function from another file in Python?

Hi@akhtar, You can use the import keyword to ...READ MORE

answered Jun 24, 2020 in Python by MD
• 95,440 points
0 votes
1 answer

How to ignore Headers in S3 bucket CSV file using python?

Hi@durgaraju, You can fetch only the body part. ...READ MORE

answered Dec 29, 2020 in Python by MD
• 95,440 points
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP