> For the complete documentation index, see [llms.txt](https://ir0nstone.gitbook.io/ai-ml/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ir0nstone.gitbook.io/ai-ml/pandas.md).

# Pandas

## Overview

[Pandas](https://pandas.pydata.org/) is an open source data analysis and manipulation tool that is ubiquitous across data science and machine learning.

We can install `pandas` using `pip` and then import

```python
import pandas as pd
```

## Data Types

Pandas has two incredibly important data types - the **DataFrame** and the **Series**.

### DataFrames

A DataFrame is a table, with each entry corresponding to a row and column. If we wanted to create a table of individuals and their respective ages and heights:

```python
df = pd.DataFrame({'Age': [22, 27], 'Height': [181, 173]})
```

When printed, it is displayed like this:

```
   Age  Height
0   22     181
1   27     173
```

We can give the rows labels by setting the `index` argument in the constructor

```
df = pd.DataFrame({'Age': [22, 27], 'Height': [181, 173]}, index=['Alice', 'Bob'])
```

```
       Age  Height
Alice   22     181
Bob     27     173
```

### Series

A Series is a sequence of data values - effectively a list. We can create one from a list:

```python
pd.Series([1, 2, 3, 4, 5])
```

```
0    1
1    2
2    3
3    4
4    5
dtype: int64
```

We can give each entry a label and also give the overall Series a name

```
pd.Series([130, 10, 30], index=['Stock ID', 'Quantity', 'Quantity To Buy'], name='Stock Info')
```

We can think of a DataFrame as a load of Series "glued" together, and this will help us when it comes to manipulating data later!

### Using Files

We can read data straight from files using functions such as [`read_csv`](https://pandas.pydata.org/docs/reference/api/pandas.read_csv.html), which is very easy to understand. The DataFrame method [`to_csv`](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.to_csv.html) allows you to save it afterwards as well. Equivalents exist for other files.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://ir0nstone.gitbook.io/ai-ml/pandas.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
