> For the complete documentation index, see [llms.txt](https://igb.mit.edu/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://igb.mit.edu/mini-courses/python/data-processing-with-python/pandas/making-dataframes.md).

# Making DataFrames

### Provide a list or numpy array

The column and row labels will simply use the numerical index

```
import pandas as pd
import numpy as np
```

```
z = np.array([[1,2,3,4,5],[6,7,8,9,10]])
z
```

<figure><img src="/files/yegycM7Zry93OfzY0Z1j" alt=""><figcaption></figcaption></figure>

```
pd.DataFrame(z) #note the difference to a numpy array z above
```

<figure><img src="/files/8tKvrrNbt6OurZuzX5en" alt=""><figcaption></figcaption></figure>

```
my_list = [['a', 'b', 'c'], [10,5,2.5], [3,2,1]]
print(my_list)
df = pd.DataFrame(my_list)
df #note the output here
```

\[\['a', 'b', 'c'], \[10, 5, 2.5], \[3, 2, 1]]

<figure><img src="/files/ssbdzr538a7LwpLMxpPa" alt=""><figcaption></figcaption></figure>

```
df.shape
```

(3, 3)

### Provide a dictionary

```
dictionary = {'a':[10,3], 'b':[5,2], 'c':[2.5,1]}
df = pd.DataFrame(dictionary)
df #note the difference with the prior dataframe you made
```

<figure><img src="/files/rcrnmHD7L9XMhhndEM3l" alt=""><figcaption></figcaption></figure>

```
df.shape #note the new shape
```

(2, 3)

```
df.columns #this is how to get a list of the column headers
```

Index(\['a', 'b', 'c'], dtype='object')

```
dictionary = {'a':{'row1':3, 'row2':2}, 'b':{'row1':5,'row2':2}, 'c':{'row1':2.5,'row2':1}}
df = pd.DataFrame(dictionary)
df #note the new index!
```

<figure><img src="/files/o9xViRo5iGxZv6xsP84N" alt=""><figcaption></figcaption></figure>

```
df.index #this is how you get a list of the row labels
```

Index(\['row1', 'row2'], dtype='object')

```
dictionary2 = {'a':{'row1':3, 'row2':2}, 'b':{'row3':5,'row4':2}, 'c':{'row5':2.5,'row6':1}}
df2 = pd.DataFrame(dictionary2)
df2
```

<figure><img src="/files/9ck9dTqlLJfdw2GJ8MTG" alt=""><figcaption></figcaption></figure>

#### Read a CSV file

```
#pandas has some great methods to read .csv files
pd.read_csv?
```

```
ms=pd.read_csv("C:\\Users\duan\Desktop\PythonDataProcessingVisualization\mass_spec.csv")
ms
```

<figure><img src="/files/NwYqA04SFObOxCOlwQyR" alt=""><figcaption></figcaption></figure>

#### Read an Excel file

```
#pandas has read_excel method to read excel files
pd.read_excel?
```

```
excelf=pd.read_excel("C:\\Users\duan\Desktop\PythonDataProcessingVisualization\excelfile.csv")
excelf
```

<figure><img src="/files/yy7MtAlCAawLQxPfTgmz" alt=""><figcaption></figcaption></figure>


---

# 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://igb.mit.edu/mini-courses/python/data-processing-with-python/pandas/making-dataframes.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.
