0

So here's the scenario:

  • I have a csv column that stores users points
  • I am able to alter the user's 'points
  • After changing them, I would like to replace the old score with the new altered one

How can I update this value?

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
  • It looks like you want SO to write code for you. Please show what you have tried and where you are getting stuck. – AChampion Aug 26 '17 at 17:03
  • I have tried to rewrite the CSV row, with the updated 'score' value already replaced. [User,Password,Score]. However this rewites on a new row, I just wanted it to replace the old equivalent. – dick romney Aug 26 '17 at 17:06
  • 2
    Possible duplicate of [How do you replace a line of text in a text file (python)](https://stackoverflow.com/questions/16622754/how-do-you-replace-a-line-of-text-in-a-text-file-python) – sKwa Aug 26 '17 at 17:06
  • @sKwa that is the wrong file type – dick romney Aug 26 '17 at 17:09
  • What method do you use for adding the new line? Please show your code. You tagged python, so it is safe to assume you have used a python script. Show that. I.e. try to get close to a [mcve]. You might also benefit from taking the [tour] and reading [ask]. – Yunnosch Aug 26 '17 at 19:45
  • If you can edit one kind of text file (using sKwa nice link) what keeps you from doing it on a different kind? – Yunnosch Aug 26 '17 at 19:47
  • You need to add the code you have worked so far in your question. That way, we can help you by finding mistakes in your code. – BusyProgrammer Aug 26 '17 at 23:24

1 Answers1

1

Make pandas data frame which takes 5 row's and 2 columns as input for example:-

import pandas as pd  
res = pd.DataFrame(columns=('col1', 'col2'))  
for i in range(5):  
    res_list = list(map(int, input().split()))  
    res = res.append(pd.Series(res_list,index=['col1','col2']), ignore_index=True)
df.to_csv('example.csv', index=False,, header=False)  

index and header values are according to your choice

Vineet Jain
  • 1,515
  • 4
  • 21
  • 31