Wrinting on a specific csv cell

I’m trying to make a little software with a tkinter GUI that interfaces with some csv files.
I would find a way to append datas inside a specific cell but I can’t find a way to do it with the built-in csv module.
I searched also in the pandas manual but it seems too complicated to use. I don’t need to do something special, simply I have to put some infos in a document for collecting datas in a specific cell of a specific column.
Could someone post some code of example?
Thanks in advance

Using pandas to write to a specific cell is very simple:

import pandas as pd
df = pd.read_csv("filename.csv")  # Load CSV file
df.A[5] = 10  # Write the value 10 to column A, row 5 (zero-indexed)
df.to_csv("filename.csv")  # Save the file

CSV files are text files with column data separated by commas.

Generally you can’t write a specific cell in an arbitrary row because if
your new datum is wider than what was there before you would need to
push all the following text further up the file, which isn’t something
you can do.

You can rewrite the whole file:

  • read the file into memory, modify the data, write it all out

You can append additional rows to the file:

 import csv

 additional_row = [1, 2, 3, "some text"]
 with open("filename.csv", "a") as csvf:
     csvw = csv.writer(csvf)
     csvw.writerow(additional_row)

There are examples of writing to CSV files in the csv module
documentation:

Depending what you want to do and how you choose to interpret the CSV
data, you can use such an approach to “change” existing data; if each
row has a primary key, you could adopt the approach that when reading
the whole file you only care about the latest row for a given key, and
then you can update by appending a new row for that key to the end of
the file.

Cheers,
Cameron Simpson cs@cskk.id.au

I tried the example you’ve posted but I get this:

Traceback (most recent call last):
  File "<string>", line 4, in <module>
  File "/.../python3.10/site-packages/pandas/core/generic.py", line 5902, in __getattr__
    return object.__getattribute__(self, name)
AttributeError: 'DataFrame' object has no attribute 'A'

‘A’ was just an example. The actual column names are whatever they are called in your csv file.