<jupyter_start><jupyter_text>Time Series in Pandas<jupyter_code>import datetime

import numpy as np
np.random.seed(0)
import pandas as pd
def series_info(series: pd.Series) -> None:
    print(f"ndim: {series.ndim}")
    print(f"shape: {series.shape}")
    print(f"size: {series.size}")
    print(f"dtype: {series.dtype}")
    print(f"values:\n{series}\n")
def df_info(df: pd.DataFrame) -> None:
    print(f"ndim: {df.ndim}")
    print(f"shape: {df.shape}")
    print(f"size: {df.size}")
    print(f"dtype: {df.dtypes}")
    print(f"values:\n{df}\n")<jupyter_output><empty_output><jupyter_text>| Concept 	| Scalar Class 	| pandas Data Type 	| Primary Creation Method 	||-	|-	|-	|-	|-	|| Date times 	| Timestamp 	| datetime64\[ns\]	| to_datetime or date_range 	|| Time deltas 	| Timedelta 	| timedelta64\[ns\] 	| to_timedelta or timedelta_range 	|| Time spans 	| Period 	| period\[freq\] 	| Period or period_range 	|<jupyter_code>ds = pd.date_range(
    "21/4/2021",
    periods=3,
    freq="H"
)
series_info(ds)
series_info(ds.tz_localize("UTC"))
friday = pd.Timestamp("2018-01-05 12:00:00").tz_localize("Europe/Berlin")

print(friday)
saturday = friday + pd.Timedelta("1 day")

print(saturday)
num_samples = 100

dates = pd.date_range(
    "21/4/2021",
    periods=num_samples
)

df = pd.DataFrame(
    {
        "Date": dates,
        "Value": np.random.randn(num_samples)
    }
)
df_info(df)
pd.Period("2021-05")
pd.Period("2021-05", freq="D")
dates = [
    pd.Timestamp("2021-05-01"),
    pd.Timestamp("2021-05-02"),
    pd.Timestamp("2021-05-04"),
]

ts = pd.Series(np.random.randn(3), dates)
series_info(ts)
start = datetime.datetime(2021, 5, 1)
end = datetime.datetime(2021, 5, 31)

index = pd.date_range(start, end)

series_info(index)
series_info(pd.date_range(start, end, freq="D"))
series_info(pd.date_range('2021-05-01', '2021-05-31', freq="D"))<jupyter_output>ndim: 1
shape: (31,)
size: 31
dtype: datetime64[ns]
values:
DatetimeIndex(['2021-05-01', '2021-05-02', '2021-05-03', '2021-05-04',
               '2021-05-05', '2021-05-06', '2021-05-07', '2021-05-08',
               '2021-05-09', '2021-05-10', '2021-05-11', '2021-05-12',
               '2021-05-13', '2021-05-14', '2021-05-15', '2021-05-16',
               '2021-05-17', '2021-05-18', '2021-05-19', '2021-05-20',
               '2021-05-21', '2021-05-22', '2021-05-23', '2021-05-24',
               '2021-05-25', '2021-05-26', '2021-05-27', '2021-05-28',
               '2021-05-29', '2021-05-30', '2021-05-31'],
              dtype='datetime64[ns]', freq='D')
{'fraction_non_alphanumeric': 0.20441988950276244, 'fraction_numerical': 0.1424625098658248, 'mean_word_length': 3.3706896551724137, 'pattern_counts': {'":': 2, '<': 8, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '484140', 'license': 'MIT', 'n_tokens_mistral': 1269, 'n_tokens_neox': 1084, 'n_words': 169, 'path': '3_Pandas/06_TimeSeries.ipynb', 'repo_name': 'tkaya94/UdemyDataScience', 'size': '2534'}