A CSV (comma-separated values) file is a plain-text table: one record per line, fields separated by a delimiter, usually a comma. Spreadsheets, databases and data-science tools can all import and export CSV, which makes it the most common format for moving tabular data between programs.
The first line is usually a header row of column names.
Fields containing the delimiter are put in quotes: "Delhi, India".
Other delimiters are possible: tab (\t), semicolon (;) or colon (:).
The csv module (standard library)
Tool
Use
csv.reader(f)
Iterates rows as lists of strings
csv.DictReader(f)
Iterates rows as dictionaries keyed by the header
csv.writer(f), writer.writerow(row)
Writes rows (quotes fields when needed)
delimiter=";"
Reads or writes another delimiter
Open CSV files with newline="", as the csv documentation recommends, so that line endings are handled correctly on every system.
pandas
pandas (pip install pandas; included in Anaconda) loads a CSV file into a DataFrame, a table with labelled columns, in one call: df = pd.read_csv("file.csv"). Columns are selected with df["column"], and each column has statistics methods: mean(), sum(), max(), min(), count(), median(), std() (sample standard deviation) and var() (sample variance); describe() shows them all at once.
By default read_csv treats the first line as the header. For a file without a header row, pass header=None, or give the names with names=[...].
Key takeaways
CSV: plain-text rows, delimiter-separated fields, usually a header line.
csv.reader/DictReader read, csv.writer writes; open with newline="".
pd.read_csv returns a DataFrame; use header=None or names= if there is no header.
Answer on paper first, then check. The explanation matters more than the letter you chose.
Question 6 · short answer
Write a program that reads sales.csv (columns region and amount) with pandas and prints the total and average amount, and the total for each region.
Show worked answer
import pandas as pd, df = pd.read_csv("sales.csv"), then print("Total:", df["amount"].sum()), print("Average:", df["amount"].mean()) and print(df.groupby("region")["amount"].sum()). read_csv uses the header line for column names; groupby("region") splits the rows by region and sum() adds the amounts in each group.
MCA Online notes are made for reading on screen. Open https://mcastudy.online/mcs-201/data-access-using-python/csv-files-in-python/ to read this page.