The code below should add a movie “blah” to a column titled “Watched Movies” in a .csv file. It works the first time you use it, but does not work the second time. the message ‘”blah” has been added to your watched movies.’ prints, but it does not actually add “blah” to the column.
file = 'C:\Users\aosog\Downloads\Spyder\A_My_Python\Random\test.csv'
olddata = pd.read_csv(file, skiprows=1, names=['Movies', 'Watched Movies'])
movies = olddata['Movies']
watched = olddata['Watched Movies']
newdata = pd.DataFrame(columns=['Movies', 'Watched Movies'])
name = "blah"
watched = pd.concat([watched, pd.Series(name)], ignore_index=True) newdata['Watched Movies'] = watched
newdata.to_csv(file)
print(f'n"{name}" has been added to your watched movies.')
New contributor
Austin Osogwin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
13