Reading and Writing Data
Real-world financial analysis starts with loading data from files. Pandas makes reading and writing data incredibly simple.
Reading CSV Files
CSV (Comma-Separated Values) is the most common format for financial data:
Loading Python Playground...
Reading with Options
Loading Python Playground...
Working with Date Indexes
Loading Python Playground...
Creating Sample Data for Practice
Since we can't read files in the browser, let's create realistic sample data:
Loading Python Playground...
Calculating Returns from Price Data
Loading Python Playground...
Writing Data (Conceptual)
Loading Python Playground...
Practice: Process Price Data
Loading Python Exercise...
Practice: Calculate Returns
Loading Python Exercise...
Key Takeaways
- Read CSV with
pd.read_csv('filename.csv') - Use
index_colto set index column - Use
parse_dates=Truefor date columns - Calculate returns with
.pct_change() - Write CSV with
df.to_csv('filename.csv') - Write Excel with
df.to_excel('filename.xlsx')
This completes Module 2! You now have the essential NumPy and Pandas skills for financial data analysis.

