Advertisement
kced20

python write read

Feb 22nd, 2019
622
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.13 KB | None | 0 0
  1. f = open('C:\\Users\\kced20\Desktop\\myread\\international.csv',"r") # this line will open the file international.csv for reading
  2. out = open("females.csv","w")   # this line will create a file called females.csv
  3. counterfemale_of_china = 0  # counter of chinese females
  4. for line in f:          # this line means loop thru each line of international.csv
  5.   line = line.strip()   # this line means that clean each line read, meaning that remove all hidden spaces, tab ....
  6.   a,b,c,d,e,f = line.split(",")  # this line means a = id, b =firstname, c= lastname, d=email , e= gender and f = country
  7.   if (e == 'Female'):   # since we know that variable e is the gender, then we compare e to Female to see if male or female
  8.     out.write(line)     # if gender = female, then write the female line information to females.csv
  9.   if (e == 'Female' and f =='China'):    # since we know that e is gender and f is country, then this line means find all female from China
  10.       counterfemale_of_china = counterfemale_of_china + 1   # this line means count the number of females and chinese  
  11.  
  12. print("The number of Chinese Female is :\t",counterfemale_of_china)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement