Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 16388

How get data from entire line in a csv file and print it in txt file using python

$
0
0

I have a hudge csv file with 15 columns and a lot of lines.I use pandas to keep only 5 columns in a new csv file.

new csv file.

ID, age, number of played game, ratio, Namexx:xx:xx:xx:xx:xx, 19, 52, 33.0, GhostHotel

What i want to do is for each index value extract them from the entire line and print each value in a txt file.

expected task.

id.txt age.txt number_of_pg.txt ratio.txt Name.txt

I use the following code but this only print one value in a row.

import csvwith open('midvalues.csv') as player:   csv_reader = csv.reader(player)   for index, row in enumerate(csv_reader):      if index == 6:           print(row[4]) 

How can i save each value to his specific txt file ?


Viewing all articles
Browse latest Browse all 16388

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>