Skip to content

Commit eba755c

Browse files
authored
Update and rename datetime_with_pandas.md to datetime.md
1 parent d02ee27 commit eba755c

File tree

1 file changed

+19
-27
lines changed

1 file changed

+19
-27
lines changed

contrib/pandas/datetime_with_pandas.md renamed to contrib/pandas/datetime.md

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,16 @@
1-
# Pandas DateTime
1+
# Working with Date & Time in Pandas
22

3-
Pandas is a robust Python library that is available as free source. The Pandas library is used to manipulate and analyse data. Pandas are made up of data structures and functions that allow for efficient data processing.
4-
5-
While working with data, it is common to come across time series data. Pandas is a very handy tool for dealing with time series data. Pandas is a strong Python data analysis toolkit that provides a wide range of date and time data processing options. Many data science jobs require working with time series data, time zones, and date arithmetic, and pandas simplifies these processes.
6-
7-
Features of Pandas `Date_Time`:
3+
While working with data, it is common to come across data containing date and time. Pandas is a very handy tool for dealing with such data and provides a wide range of date and time data processing options.
84

95
- **Parsing dates and times**: Pandas provides a number of functions for parsing dates and times from strings, including `to_datetime()` and `parse_dates()`. These functions can handle a variety of date and time formats, Unix timestamps, and human-readable formats.
106

117
- **Manipulating dates and times**: Pandas provides a number of functions for manipulating dates and times, including `shift()`, `resample()`, and `to_timedelta()`. These functions can be used to add or subtract time periods, change the frequency of a time series, and calculate the difference between two dates or times.
128

139
- **Visualizing dates and times**: Pandas provides a number of functions for visualizing dates and times, including `plot()`, `hist()`, and `bar()`. These functions can be used to create line charts, histograms, and bar charts of date and time data.
1410

11+
### `Timestamp` function
1512

16-
17-
### Installation of libraries
18-
19-
`pip install pandas`
20-
21-
- **Note**: There is no need to install a seperate library for date_time operations, pandas module itself has built-in functions.
13+
The timestamp function in Pandas is used to convert a datetime object to a Unix timestamp. A Unix timestamp is a numerical representation of datetime.
2214

2315
Example for retrieving day, month and year from given date:
2416

@@ -35,15 +27,13 @@ print('Day is: ', d)
3527
```
3628

3729
Output:
30+
3831
```python
3932
Year is: 2024
4033
Month is: 5
4134
Day is: 5
4235
```
4336

44-
- **Note**: The timestamp function in Pandas is used to convert a datetime object to a Unix timestamp. A Unix timestamp is a numerical representation of datetime.
45-
46-
4737
Example for extracting time related data from given date:
4838

4939
```python
@@ -57,13 +47,16 @@ print('Quarter is: ', ts.quarter)
5747
```
5848

5949
Output:
50+
6051
```python
6152
Hour is: 12
6253
Minute is: 0
6354
Weekday is: 1
6455
Quarter is: 4
6556
```
6657

58+
### `Timestamp.now()`
59+
6760
Example for getting current date and time:
6861

6962
```python
@@ -78,6 +71,8 @@ Output:
7871
Current date and time is: 2024-05-25 11:48:25.593213
7972
```
8073

74+
### `date_range` function
75+
8176
Example for generating dates' for next five days:
8277

8378
```python
@@ -89,6 +84,7 @@ for i in ts:
8984
```
9085

9186
Output:
87+
9288
```python
9389
2024-05-25
9490
2024-05-26
@@ -116,11 +112,11 @@ Output:
116112
2024-05-25
117113
```
118114

119-
### Pandas `DateTime` is Efficient than Built-in `DateTime` library in various aspects like:
115+
### Built-in vs pandas date & time operations
120116

121-
- **In pandas, you may add a time delta to a full column of dates in a single action, but Python's datetime requires a loop.**
117+
In `pandas`, you may add a time delta to a full column of dates in a single action, but Python's datetime requires a loop.
122118

123-
Example using Pandas DateTime:
119+
Example in Pandas:
124120

125121
```python
126122
import pandas as pd
@@ -146,7 +142,7 @@ Output:
146142
99999 2023-03-12 10:39:00
147143
```
148144

149-
Example using Built-In datetime library:
145+
Example using Built-in datetime library:
150146

151147
```python
152148
from datetime import datetime, timedelta
@@ -155,12 +151,8 @@ dates = [datetime(2023, 1, 1) + timedelta(minutes=i) for i in range(100000)]
155151
dates = [date + timedelta(days=1) for date in dates]
156152
```
157153

158-
Output:
159-
```The output is very large to display and taking more time to display```
160-
161-
162-
- **Pandas employs NumPy's datetime64 dtype, which takes up a set amount of bytes (usually 8 bytes per date), to store datetime data more compactly and efficiently.**
163-
- **Each datetime object in Python takes up extra memory since it contains not only the date and time but also the additional metadata and overhead associated with Python objects.**
154+
Why use pandas functions?
164155

165-
- **Pandas Offers a wide range of convenient functions and methods for date manipulation, extraction, and conversion, such as `pd.to_datetime()`, `date_range()`, `timedelta_range()`, and more.**
166-
- **datetime library requires manual implementation for many of these operations, leading to longer and less efficient code.**
156+
- Pandas employs NumPy's datetime64 dtype, which takes up a set amount of bytes (usually 8 bytes per date), to store datetime data more compactly and efficiently.
157+
- Each datetime object in Python takes up extra memory since it contains not only the date and time but also the additional metadata and overhead associated with Python objects.
158+
- Pandas Offers a wide range of convenient functions and methods for date manipulation, extraction, and conversion, such as `pd.to_datetime()`, `date_range()`, `timedelta_range()`, and more. datetime library requires manual implementation for many of these operations, leading to longer and less efficient code.

0 commit comments

Comments
 (0)