---
description: In computer programming, pandas is a software library written for the Python programming language for data manipulation and analysis. In particular, it offers data structures and operations for manipu
title: "Python Pandas Tutorial: DataFrame, Date Range &#038; Use"
image: https://www.guru99.com/images/python-pandas-tutorial.png
---

[Skip to content](#main)

**⚡ Smart Summary**

Pandas is the open-source Python library for manipulating tabular data. It supplies the Series and DataFrame structures, date ranges, inspection helpers and the slice, drop, concatenate, sort and rename operations demonstrated throughout this walkthrough.

- 🔘 **Built on NumPy:** Pandas requires NumPy, which supplies the arrays behind every Series and DataFrame.
- ☑️ **Two structures:** Series stores one labelled dimension; DataFrame stores rows and columns of mixed types.
- ✅ **Date ranges:** pd.date\_range() builds an index from a start date, a period count and a frequency.
- 🧪 **Inspect first:** head(), tail() and describe() reveal shape, spread and percentiles before any analysis.
- 🛠️ **Slice precisely:** Bracket names select columns, loc selects by label and iloc selects by position.
- ⚠️ **Version note:** The frequency alias M is deprecated from Pandas 2.2; current releases expect ME.

Read More

![Python Pandas Tutorial: DataFrame, Date Range and Use of Pandas](https://www.guru99.com/images/python-pandas-tutorial.png)

## What is Pandas in Python?

**Pandas** is an open-source library that lets you perform data manipulation and analysis in Python, covering numerical tables and time series alike. It provides an easy way to create, manipulate and wrangle data, and it is built on top of [NumPy](https://www.guru99.com/numpy-tutorial.html), so NumPy must be present for Pandas to operate.

## Why use Pandas?

Data scientists make use of Pandas in Python for the following advantages:

- Easily handles missing data
- It uses Series for one-dimensional data and DataFrame for multi-dimensional data
- It provides an efficient way to slice the data
- It provides a flexible way to merge, concatenate or reshape the data
- It includes a powerful time series toolkit

In short, Pandas supplies powerful, easy-to-use data structures plus the means to operate on them quickly, which is why it anchors most Python [data analysis](https://www.guru99.com/what-is-data-analysis.html) work.

## How to Install Pandas

Pandas ships with Anaconda and with most managed notebook services, so it is usually installed already. If the import fails, one of the commands below adds it. The environment built in [How to install TensorFlow](https://www.guru99.com/download-install-tensorflow.html) also contains Pandas.

- pip: `pip install pandas`
- Anaconda: `conda install -c anaconda pandas`
- Inside a [Jupyter Notebook](https://www.guru99.com/jupyter-notebook-tutorial.html) cell:

```
import sys
!conda install --yes --prefix {sys.prefix} pandas
```

## What is a Pandas DataFrame?

A Pandas DataFrame is a two-dimensional labelled data structure whose columns may hold different types. It is the standard way to store data in tabular format: rows hold the observations and columns name the information. For instance, *price* can be the name of a column and 2, 3, 4 can be the price values.

Data frames are well known to statisticians and other data practitioners. The picture below shows that shape — a labelled row index down the side and named columns across the top.

[![Pandas DataFrame layout with a labelled row index and named columns]()](https://www.guru99.com/images/tensorflow/082918_0617_PandasTutor1.png)

## What is a Series?

A Series is a one-dimensional data structure. It can hold any data type, such as integer, float or string, and is useful when you want to perform a computation or return a one-dimensional array. A Series, by definition, cannot have multiple columns; for that case use the DataFrame structure.

The Pandas Series constructor takes the following parameters:

- **Data:** can be a list, dictionary or scalar value

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

```
0    1.0
1    2.0
2    3.0
dtype: float64
```

You can add an index with `index`. It names the rows, and its length must equal the size of the column.

```
pd.Series([1., 2., 3.], index=['a', 'b', 'c'])
```

Below you create a Pandas Series with a missing value in the third row. Missing values in Python are shown as `NaN`, and `np.nan` from NumPy creates one artificially.

```
pd.Series([1,2,np.nan])
```

Output

```
0    1.0
1    2.0
2    NaN
dtype: float64

```

## Create Pandas DataFrame

You can convert a NumPy array into a DataFrame with `pd.DataFrame()`. The opposite is also possible: to convert a DataFrame back into an array, use `np.array()`, or `df.to_numpy()`, which current Pandas documentation recommends.

```
## Numpy to pandas
import numpy as np
h = [[1,2],[3,4]] 
df_h = pd.DataFrame(h)
print('Data Frame:', df_h)

## Pandas to numpy
df_h_n = np.array(df_h)
print('Numpy array:', df_h_n)
Data Frame:    0  1
0  1  2
1  3  4
Numpy array: [[1 2]
 [3 4]]

```

A dictionary works just as well as an input to `pd.DataFrame()`.

```
dic = {'Name': ["John", "Smith"], 'Age': [30, 40]}
pd.DataFrame(data=dic)
```

|  | Age | Name |
| --- | --- | --- |
| 0 | 30 | John |
| 1 | 40 | Smith |

**Don't Miss:**

- [TensorBoard Tutorial: TensorFlow Graph Visualization](https://www.guru99.com/tensorboard-tutorial.html)
- [Linear Regression Tutorial with TensorFlow \[Examples\]](https://www.guru99.com/linear-regression-tensorflow.html "Linear Regression Tutorial with TensorFlow [Examples]")
- [RNN (Recurrent Neural Network) Tutorial: TensorFlow Example](https://www.guru99.com/rnn-tutorial.html)
- [Pandas Cheat Sheet for Data Science in Python](https://www.guru99.com/pandas-cheat-sheet-for-data-science.html)

## Pandas Range Data

Pandas has a convenient API for creating a range of dates, which becomes the index of a time series. The call takes this form:

`pd.date_range(start, periods, freq):`

- The first parameter is the starting date
- The second parameter is the number of periods (optional if the end date is specified)
- The last parameter is the frequency: day `D`, month `M` and year `Y`

```
## Create date
# Days
dates_d = pd.date_range('20300101', periods=6, freq='D')
print('Day:', dates_d)

```

Output

```
Day: DatetimeIndex(['2030-01-01', '2030-01-02', '2030-01-03', '2030-01-04', '2030-01-05', '2030-01-06'], dtype='datetime64[ns]', freq='D')

```

```
# Months
dates_m = pd.date_range('20300101', periods=6, freq='M')
print('Month:', dates_m)

```

Output

```
Month: DatetimeIndex(['2030-01-31', '2030-02-28', '2030-03-31', '2030-04-30','2030-05-31', '2030-06-30'], dtype='datetime64[ns]', freq='M')

```

**Version note:** the month alias `M` used above is deprecated from Pandas 2.2 and removed in Pandas 3.0. On current releases pass `freq='ME'` for month end; the resulting index is identical.

## Inspecting Data

You can check the head or tail of a dataset with `head()` or `tail()` called on the DataFrame, as the Pandas example below shows.

**Step 1)** Create a random sequence with NumPy. The sequence has 4 columns and 6 rows.

```
random = np.random.randn(6,4)
```

**Step 2)** Then you create a DataFrame using Pandas.

Use `dates_m` as the index, so each row is given a name corresponding to a date, and name the 4 columns with the `columns` argument.

```
# Create data with date
df = pd.DataFrame(random,
                  index=dates_m,
                  columns=list('ABCD'))

```

Because `np.random.randn()` runs without a seed, your figures will differ from the ones printed here. Call `np.random.seed(0)` first if you want to reproduce a fixed set.

**Step 3)** Using the head function

```
df.head(3)
```

|  | A | B | C | D |
| --- | --- | --- | --- | --- |
| 2030-01-31 | 1.139433 | 1.318510 | -0.181334 | 1.615822 |
| 2030-02-28 | -0.081995 | -0.063582 | 0.857751 | -0.527374 |
| 2030-03-31 | -0.519179 | 0.080984 | -1.454334 | 1.314947 |

**Step 4)** Using the tail function

```
df.tail(3)
```

|  | A | B | C | D |
| --- | --- | --- | --- | --- |
| 2030-04-30 | -0.685448 | -0.011736 | 0.622172 | 0.104993 |
| 2030-05-31 | -0.935888 | -0.731787 | -0.558729 | 0.768774 |
| 2030-06-30 | 1.096981 | 0.949180 | -0.196901 | -0.471556 |

**Step 5)** An excellent way to get a clue about the data is `describe()`. It reports the count, mean, std, min, max and percentiles of the dataset.

```
df.describe()
```

|  | A | B | C | D |
| --- | --- | --- | --- | --- |
| count | 6.000000 | 6.000000 | 6.000000 | 6.000000 |
| mean | 0.002317 | 0.256928 | -0.151896 | 0.467601 |
| std | 0.908145 | 0.746939 | 0.834664 | 0.908910 |
| min | -0.935888 | -0.731787 | -1.454334 | -0.527374 |
| 25% | -0.643880 | -0.050621 | -0.468272 | -0.327419 |
| 50% | -0.300587 | 0.034624 | -0.189118 | 0.436883 |
| 75% | 0.802237 | 0.732131 | 0.421296 | 1.178404 |
| max | 1.139433 | 1.318510 | 0.857751 | 1.615822 |

## Slice Data

Slicing pulls a subset of rows or columns out of a DataFrame. You can use the column name to extract one column, as the Pandas example below shows.

```
## Slice
### Using name
df['A']

2030-01-31   -0.168655
2030-02-28    0.689585
2030-03-31    0.767534
2030-04-30    0.557299
2030-05-31   -1.547836
2030-06-30    0.511551
Freq: M, Name: A, dtype: float64

```

To select multiple columns you need a double bracket, `[[..,..]]`. The first pair means you want to select columns; the second pair states which columns to return.

```
df[['A', 'B']]
```

|  | A | B |
| --- | --- | --- |
| 2030-01-31 | -0.168655 | 0.587590 |
| 2030-02-28 | 0.689585 | 0.998266 |
| 2030-03-31 | 0.767534 | -0.940617 |
| 2030-04-30 | 0.557299 | 0.507350 |
| 2030-05-31 | -1.547836 | 1.276558 |
| 2030-06-30 | 0.511551 | 1.572085 |

You can slice the rows with a colon. The code below returns the first three rows.

```
### using a slice for row
df[0:3]
```

|  | A | B | C | D |
| --- | --- | --- | --- | --- |
| 2030-01-31 | -0.168655 | 0.587590 | 0.572301 | -0.031827 |
| 2030-02-28 | 0.689585 | 0.998266 | 1.164690 | 0.475975 |
| 2030-03-31 | 0.767534 | -0.940617 | 0.227255 | -0.341532 |

The `loc` accessor selects columns by name. As usual, the value before the comma stands for the rows and the value after it for the columns, and brackets are needed to select more than one column.

```
## Multi col
df.loc[:,['A','B']]
```

|  | A | B |
| --- | --- | --- |
| 2030-01-31 | -0.168655 | 0.587590 |
| 2030-02-28 | 0.689585 | 0.998266 |
| 2030-03-31 | 0.767534 | -0.940617 |
| 2030-04-30 | 0.557299 | 0.507350 |
| 2030-05-31 | -1.547836 | 1.276558 |
| 2030-06-30 | 0.511551 | 1.572085 |

There is another method for selecting multiple rows and columns. `iloc[]` uses integer positions instead of column names, so the code below returns the same DataFrame as above.

```
df.iloc[:, :2]
```

|  | A | B |
| --- | --- | --- |
| 2030-01-31 | -0.168655 | 0.587590 |
| 2030-02-28 | 0.689585 | 0.998266 |
| 2030-03-31 | 0.767534 | -0.940617 |
| 2030-04-30 | 0.557299 | 0.507350 |
| 2030-05-31 | -1.547836 | 1.276558 |
| 2030-06-30 | 0.511551 | 1.572085 |

## Drop a Column

You can drop columns with `df.drop()`, passing the names in the `columns` argument.

```
df.drop(columns=['A', 'C'])
```

|  | B | D |
| --- | --- | --- |
| 2030-01-31 | 0.587590 | -0.031827 |
| 2030-02-28 | 0.998266 | 0.475975 |
| 2030-03-31 | -0.940617 | -0.341532 |
| 2030-04-30 | 0.507350 | -0.296035 |
| 2030-05-31 | 1.276558 | 0.523017 |
| 2030-06-30 | 1.572085 | -0.594772 |

## Concatenation

You can concatenate two DataFrames with `pd.concat()`. First create the two frames.

```
import numpy as np
df1 = pd.DataFrame({'name': ['John', 'Smith','Paul'],
                     'Age': ['25', '30', '50']},
                    index=[0, 1, 2])
df2 = pd.DataFrame({'name': ['Adam', 'Smith' ],
                     'Age': ['26', '11']},
                    index=[3, 4])  

```

Then concatenate them.

```
df_concat = pd.concat([df1,df2]) 
df_concat
```

|  | Age | name |
| --- | --- | --- |
| 0 | 25 | John |
| 1 | 30 | Smith |
| 2 | 50 | Paul |
| 3 | 26 | Adam |
| 4 | 11 | Smith |

## Drop Duplicates

When a dataset contains duplicate information, `drop_duplicates()` is an easy way to exclude the repeated rows. `df_concat` holds a duplicate observation: `Smith` appears twice in the `name` column.

```
df_concat.drop_duplicates('name')
```

|  | Age | name |
| --- | --- | --- |
| 0 | 25 | John |
| 1 | 30 | Smith |
| 2 | 50 | Paul |
| 3 | 26 | Adam |

## Sort Values

You can sort a frame with `sort_values()`. Note that `Age` was created as text here, so the rows sort in string order.

```
df_concat.sort_values('Age')
```

|  | Age | name |
| --- | --- | --- |
| 4 | 11 | Smith |
| 0 | 25 | John |
| 3 | 26 | Adam |
| 1 | 30 | Smith |
| 2 | 50 | Paul |

## Rename Columns

Use `rename()` to rename a column in Pandas. In each pair the first value is the current column name and the second is the new one.

```
df_concat.rename(columns={"name": "Surname", "Age": "Age_ppl"})
```

|  | Age\_ppl | Surname |
| --- | --- | --- |
| 0 | 25 | John |
| 1 | 30 | Smith |
| 2 | 50 | Paul |
| 3 | 26 | Adam |
| 4 | 11 | Smith |

## Pandas Methods Quick Reference

This table maps each common task to the Pandas method that performs it.

| Task | Method |
| --- | --- |
| import data | read\_csv |
| create series | Series |
| Create Dataframe | DataFrame |
| Create date range | date\_range |
| return head | head |
| return tail | tail |
| Describe | describe |
| slice using name | dataname\[‘columnname’] |
| Slice using rows | data\_name\[0:5] |

## FAQs

📥 How do you load a CSV file into a DataFrame?

Call [pd.read\_csv()](https://www.guru99.com/pandas-read-csv.html) with a path or URL. Add names to label columns, sep for a different delimiter and usecols to keep only the columns you need.

🧹 How does Pandas handle missing values?

isnull() flags them, dropna() removes the affected rows or columns, and fillna() substitutes a constant or a statistic such as the column mean. Missing entries print as NaN.

📊 What does groupby() do in Pandas?

groupby() splits rows into groups by a key column, applies an aggregation such as count, sum or mean to each group, then combines the results into a new frame.

🔍 How do you filter rows by a condition?

Build a boolean mask and pass it in brackets, for example df\[df.Age == 30]. Combine masks with the ampersand and pipe operators, wrapping each comparison in parentheses.

🔗 How do you join two DataFrames on a shared key?

pd.merge() matches rows on a key column the way a [SQL](https://www.guru99.com/sql.html) join does, with how set to inner, left, right or outer. concat() stacks frames instead of matching keys.

💾 How do you export a DataFrame to CSV or Excel?

df.to\_csv(‘out.csv’, index=False) writes a comma file, and df.to\_excel(‘out.xlsx’) writes a worksheet. Dropping the index avoids an unnamed first column on the next read.

🤖 How does AI speed up exploratory analysis in Pandas?

AI assistants profile a new frame, propose the describe, groupby and plot calls worth running, and flag columns with odd dtypes or many nulls. Confirm every suggestion against the raw data.

🧠 Can GitHub Copilot generate Pandas code inside Jupyter?

Yes. [GitHub Copilot](https://github.com/features/copilot) completes a plain comment into working Pandas code in a [Jupyter](https://www.guru99.com/jupyter-notebook-tutorial.html) cell. Review the dtypes and row counts before trusting the result.

#### Summarize this post with:

ChatGPTPerplexityGrokGoogle AI

**Stay Updated on AI** **Get Weekly AI Skills, Trends, Actionable Advice.**

##### Sign up for the newsletter

Subscribe for Free

You have successfully subscribed.  
Please check your inbox.

![AI-Newsletter]() Chosen by over **350,000+** professionals

[Scroll to top](#wrapper)

×

Search for:

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://www.guru99.com/#organization","name":"Guru99","sameAs":["https://www.facebook.com/Guru99Official","https://twitter.com/guru99com"],"logo":{"@type":"ImageObject","@id":"https://www.guru99.com/#logo","url":"https://www.guru99.com/images/guru99-logo-v1-150x59.png","contentUrl":"https://www.guru99.com/images/guru99-logo-v1-150x59.png","caption":"Guru99","inLanguage":"en-US"}},{"@type":"WebSite","@id":"https://www.guru99.com/#website","url":"https://www.guru99.com","name":"Guru99","publisher":{"@id":"https://www.guru99.com/#organization"},"inLanguage":"en-US"},{"@type":"ImageObject","@id":"https://www.guru99.com/images/python-pandas-tutorial.png","url":"https://www.guru99.com/images/python-pandas-tutorial.png","width":"700","height":"250","caption":"Python Pandas Tutorial","inLanguage":"en-US"},{"@type":"BreadcrumbList","@id":"https://www.guru99.com/python-pandas-tutorial.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":"1","item":{"@id":"https://www.guru99.com","name":"Home"}},{"@type":"ListItem","position":"2","item":{"@id":"https://www.guru99.com/tensorflow","name":"TensorFlow"}},{"@type":"ListItem","position":"3","item":{"@id":"https://www.guru99.com/python-pandas-tutorial.html","name":"Python Pandas Tutorial: DataFrame, Date Range &#038; Use"}}]},{"@type":"WebPage","@id":"https://www.guru99.com/python-pandas-tutorial.html#webpage","url":"https://www.guru99.com/python-pandas-tutorial.html","name":"Python Pandas Tutorial: DataFrame, Date Range &#038; Use","dateModified":"2026-10-09T18:21:46+05:30","isPartOf":{"@id":"https://www.guru99.com/#website"},"primaryImageOfPage":{"@id":"https://www.guru99.com/images/python-pandas-tutorial.png"},"inLanguage":"en-US","breadcrumb":{"@id":"https://www.guru99.com/python-pandas-tutorial.html#breadcrumb"}},{"@type":"Person","@id":"https://www.guru99.com/author/editorial","name":"Editorial Team","url":"https://www.guru99.com/author/editorial","image":{"@type":"ImageObject","@id":"https://www.guru99.com/images/favicon-new-logo.png","url":"https://www.guru99.com/images/favicon-new-logo.png","caption":"Editorial Team","inLanguage":"en-US"},"sameAs":["https://www.guru99.com/editorial-team"],"worksFor":{"@id":"https://www.guru99.com/#organization"}},{"articleSection":"TensorFlow","headline":"Python Pandas Tutorial: DataFrame, Date Range &#038; Use","description":"In computer programming, pandas is a software library written for the Python programming language for data manipulation and analysis. In particular, it offers data structures and operations for manipu","keywords":"tensorflow, Data Warehousing, Tableau","speakable":{"@type":"SpeakableSpecification","cssSelector":[".entry-title",".summary"]},"@type":"Article","author":{"@id":"https://www.guru99.com/author/editorial","name":"Editorial Team"},"dateModified":"2026-10-09T18:21:46+05:30","image":{"@id":"https://www.guru99.com/images/python-pandas-tutorial.png"},"copyrightYear":"2026","name":"Python Pandas Tutorial: DataFrame, Date Range &#038; Use","subjectOf":[{"@type":"FAQPage","mainEntity":[{"@type":"Question","name":"How do you load a CSV file into a DataFrame?","acceptedAnswer":{"@type":"Answer","text":"Call pd.read_csv() with a path or URL. Add names to label columns, sep for a different delimiter and usecols to keep only the columns you need."}},{"@type":"Question","name":"How does Pandas handle missing values?","acceptedAnswer":{"@type":"Answer","text":"isnull() flags them, dropna() removes the affected rows or columns, and fillna() substitutes a constant or a statistic such as the column mean. Missing entries print as NaN."}},{"@type":"Question","name":"What does groupby() do in Pandas?","acceptedAnswer":{"@type":"Answer","text":"groupby() splits rows into groups by a key column, applies an aggregation such as count, sum or mean to each group, then combines the results into a new frame."}},{"@type":"Question","name":"How do you filter rows by a condition?","acceptedAnswer":{"@type":"Answer","text":"Build a boolean mask and pass it in brackets, for example df[df.Age == 30]. Combine masks with the ampersand and pipe operators, wrapping each comparison in parentheses."}},{"@type":"Question","name":"How do you join two DataFrames on a shared key?","acceptedAnswer":{"@type":"Answer","text":"pd.merge() matches rows on a key column the way a SQL join does, with how set to inner, left, right or outer. concat() stacks frames instead of matching keys."}},{"@type":"Question","name":"How do you export a DataFrame to CSV or Excel?","acceptedAnswer":{"@type":"Answer","text":"df.to_csv('out.csv', index=False) writes a comma file, and df.to_excel('out.xlsx') writes a worksheet. Dropping the index avoids an unnamed first column on the next read."}},{"@type":"Question","name":"How does AI speed up exploratory analysis in Pandas?","acceptedAnswer":{"@type":"Answer","text":"AI assistants profile a new frame, propose the describe, groupby and plot calls worth running, and flag columns with odd dtypes or many nulls. Confirm every suggestion against the raw data."}},{"@type":"Question","name":"Can GitHub Copilot generate Pandas code inside Jupyter?","acceptedAnswer":{"@type":"Answer","text":"Yes. GitHub Copilot completes a plain comment into working Pandas code in a Jupyter cell. Review the dtypes and row counts before trusting the result."}}]}],"@id":"https://www.guru99.com/python-pandas-tutorial.html#schema-1152368","isPartOf":{"@id":"https://www.guru99.com/python-pandas-tutorial.html#webpage"},"publisher":{"@id":"https://www.guru99.com/#organization"},"inLanguage":"en-US","mainEntityOfPage":{"@id":"https://www.guru99.com/python-pandas-tutorial.html#webpage"}}]}
```
