Unable to add a new column to csv

Viewed 36

I am working with College.csv dataset. This dataset contains columns Enroll and Top10perc.

enter image description here

I want to add new column Elite, which will contain Yes if number of the proportion of students coming from the top 10 % of their high school classes exceeds 50%, otherwise No:

import pandas as pd
import matplotlib.pyplot as plt
import csv

df = pd.read_csv('College.csv')
print(df.head())

v = open('College.csv')
r = csv.reader(v)
row0 = next(r)
row0.append('Elite')
for item in r:
    if 2*int(item[5])>int(item[4]):
        item.append('Yes')
    else:
        item.append('No')
print(df.head())

However, file College.csv is unchanged and doesn't contain new column Elite.

0 Answers
Related