HI

I have .csv file which contains 3 columns ( feature 1 , feature 2 , class )

I need to take 13 row each time from f1,f2 with "1" at the end and save it into another .csv file

so if the file contains

f1 f2 class
1 1 1
2 2 1
3 3 1
4 4 1
5 5 1
6 6 1
7 7 1
8 8 1
9 9 1
10 10 1
11 11 1
12 12 1
13 13 1

it should be some thing like this

features class
1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 1

This small tutorial will teach you how to read and write csv files with python. You can post your code here if there are issues.

I have just started learning python and now I'm just importing the .csv file into lists

import csv

original = file('file1.csv')
reader = csv.reader(original)

    #will print each row by itself (all columns from names up to what they wear)
for row in csv.reader(original):

        print row

Here is how you can fetch 13 rows from the csv file (python 3 code)

import csv
import itertools as itt

with open('file1.csv', 'rt') as f:
    reader = csv.reader(f)
    rows = list(itt.islice(reader, 13))

Thanks Gribouillis

I need to take the contents of 1st two rows (in pair) (1 1) until the 13 (pair rows , f1 ,f2 )

like this :

row 1 ,row 2, ......row13 1

(1) is the last column (class)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.