CBSE 2026 · Central · Set 4 · Q33 · 4 marks
A csv file "States.csv" contains some data about all the states of India. Each record of the file contains the following data : - Name of the State - Capital of the State - Population of the State - Official Language of the State For example, a sample record in the file is:
['Andhra Pradesh','Amaravati',52221000,'Telugu']
Write a Python program which reads the data from this file and appends all those records where population is more than $\displaystyle 10000000$ into another csv file 'More.csv'. Note : "States.csv" also contains the Header row. The Header row should NOT be copied to "More.csv".
['Andhra Pradesh','Amaravati',52221000,'Telugu']
Write a Python program which reads the data from this file and appends all those records where population is more than $\displaystyle 10000000$ into another csv file 'More.csv'. Note : "States.csv" also contains the Header row. The Header row should NOT be copied to "More.csv".Marking-scheme solution
import csv
with open('States.csv') as F1 :
with open('More.csv','a',newline='') as F2:
# file mode 'w' is also acceptable
R=csv.reader(F1)
W=csv.writer(F2)
RECS=list(R)
for rec in RECS[1:]: #skipping the Header row
if int(rec[2])>10000000:
W.writerow(rec)OR
import csv
F1=open('States.csv')
F2=open('More.csv','a') # mode 'w' is also acceptable
R=csv.reader(F1)
W=csv.writer(F2)
RECS=list(R)
for rec in RECS[1:]: #skipping the Header row
if int(rec[2])>10000000:
W.writerow(rec)
F1.close()
F2.close()OR
import csv
F1=open("States.csv","r")
R=list(csv.reader(F1))
Data=[]
for rec in R[1:]: #skipping the Header row
if int(rec[2])>10000000:
Data.append(rec)
F1.close()
F2=open("More.csv","w")
W=csv.writer(F2)
W.writerows(Data)
F2.close()OR
Any similar, equivalent, correct codeFile Handling - CSV FilesReading using reader()Applycase_study
CBSE Class 12 Computer Science past-paper question from the 2026board exam, with the answer as CBSE’s own marking scheme gives it. Where our answers come from.