### Initialize DataFrame for JSON examples Source: https://pandas.pydata.org/docs/reference/api/pandas.read_json.html Setup a sample DataFrame to demonstrate JSON serialization and deserialization. ```python >>> from io import StringIO >>> df = pd.DataFrame( ... [["a", "b"], ["c", "d"]], ... index=["row 1", "row 2"], ... columns=["col 1", "col 2"], ... ) ``` -------------------------------- ### DataFrame Setup for GroupBy Pipe Example Source: https://pandas.pydata.org/docs/whatsnew/v0.21.0.html Initializes a DataFrame with store, product, revenue, and quantity data for demonstrating the GroupBy pipe method. ```python import numpy as np n = 1000 df = pd.DataFrame({'Store': np.random.choice(['Store_1', 'Store_2'], n), 'Product': np.random.choice(['Product_1', 'Product_2', 'Product_3' ], n), 'Revenue': (np.random.random(n) * 50 + 10).round(2), 'Quantity': np.random.randint(1, 10, size=n)}) df.head(2) ``` -------------------------------- ### Initialize a Pandas Series Source: https://pandas.pydata.org/docs/whatsnew/v0.13.0.html Demonstrates the initialization of a Pandas Series. This is a basic setup for subsequent examples. ```python In [96]: s = pd.Series([1, 2, 3, 4]) ``` -------------------------------- ### Create a Pandas DataFrame Source: https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.to_json.html Initializes a sample DataFrame for demonstrating JSON conversion. This setup is common across various `to_json` examples. ```python from json import loads, dumps import pandas as pd df = pd.DataFrame( [["a", "b"], ["c", "d"]], index=["row 1", "row 2"], columns=["col 1", "col 2"], ) ``` -------------------------------- ### Serialize a pandas DataFrame to a pickle file Source: https://pandas.pydata.org/docs/reference/api/pandas.Series.to_pickle.html This example demonstrates how to create a pandas DataFrame and then serialize it to a file named 'dummy.pkl' using the `to_pickle` method. Ensure you have pandas installed (`pip install pandas`). ```python import pandas as pd original_df = pd.DataFrame( {"foo": range(5), "bar": range(5, 10)} ) print(original_df) original_df.to_pickle("./dummy.pkl") ``` -------------------------------- ### Get Fiscal Year of Period with pandas Series.dt.qyear Source: https://pandas.pydata.org/docs/reference/api/pandas.Series.dt.qyear.html Demonstrates how to use the Series.dt.qyear accessor to retrieve the fiscal year of a pandas Period. It shows examples where the fiscal year aligns with the calendar year and where it differs due to a custom fiscal year start. ```python import pandas as pd # Example 1: Natural and fiscal year are the same per_same_year = pd.Period('2018Q1', freq='Q') print(f'Period: {per_same_year}, qyear: {per_same_year.qyear}, year: {per_same_year.year}') # Example 2: Fiscal year starts in April (Q-MAR) per_diff_year = pd.Period('2018Q1', freq='Q-MAR') print(f'Period: {per_diff_year}, start_time: {per_diff_year.start_time}, qyear: {per_diff_year.qyear}, year: {per_diff_year.year}') ``` -------------------------------- ### Build pandas with setuptools Source: https://pandas.pydata.org/docs/development/contributing_environment.html Legacy method to compile and install pandas using setup.py. Note that this method is deprecated. ```bash python setup.py develop ``` -------------------------------- ### Get Day of Week for a Period (pandas) Source: https://pandas.pydata.org/docs/reference/api/pandas.Period.day_of_week.html Demonstrates how to retrieve the day of the week (Monday=0, Sunday=6) for a pandas Period object. It shows examples for hourly, multi-day spanning, and monthly frequencies, illustrating how the start or end of the period is used depending on the frequency. ```python import pandas as pd # Hourly frequency per_h = pd.Period('2017-12-31 22:00', 'h') print(f"Hourly period day of week: {per_h.day_of_week}") # Multi-day spanning frequency (e.g., 4 hours) per_4h = pd.Period('2017-12-31 22:00', '4h') print(f"4-hour period day of week: {per_4h.day_of_week}") print(f"Start time of 4-hour period day of week: {per_4h.start_time.day_of_week}") # Monthly frequency per_m = pd.Period('2018-01', 'M') print(f"Monthly period day of week: {per_m.day_of_week}") print(f"End time of monthly period day of week: {per_m.end_time.day_of_week}") ``` -------------------------------- ### Setting Startup Options in IPython Source: https://pandas.pydata.org/docs/user_guide/options.html Provides an example of a Python script to be used in the IPython startup directory for automatically setting Pandas options when an IPython session begins. ```python import pandas as pd # Set common display options for an IPython session pd.set_option("display.max_rows", 999) pd.set_option("display.precision", 5) ``` -------------------------------- ### Get Starting Month for BHalfYearBegin Offset Source: https://pandas.pydata.org/docs/reference/api/pandas.tseries.offsets.HalfYearBegin.startingMonth.html Retrieves the starting month for the BHalfYearBegin offset. This indicates that half-years start in January. ```python >>> pd.offsets.BHalfYearBegin().startingMonth 1 ``` -------------------------------- ### Initialize DataFrame for idxmin examples Source: https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.idxmin.html Create a sample DataFrame representing food consumption and CO2 emissions to demonstrate index retrieval. ```python >>> df = pd.DataFrame( ... { ... "consumption": [10.51, 103.11, 55.48], ... "co2_emissions": [37.2, 19.66, 1712], ... }, ... index=["Pork", "Wheat Products", "Beef"], ... ) ``` ```python >>> df consumption co2_emissions Pork 10.51 37.20 Wheat Products 103.11 19.66 Beef 55.48 1712.00 ``` -------------------------------- ### Get BHalfYearEnd starting month Source: https://pandas.pydata.org/docs/reference/api/pandas.tseries.offsets.BHalfYearBegin.startingMonth.html Retrieve the default starting month for BHalfYearEnd offsets. This is typically June. ```python >>> pd.offsets.BHalfYearEnd().startingMonth 6 ``` -------------------------------- ### Get BHalfYearBegin starting month Source: https://pandas.pydata.org/docs/reference/api/pandas.tseries.offsets.BHalfYearBegin.startingMonth.html Retrieve the default starting month for BHalfYearBegin offsets. This is typically January. ```python >>> pd.offsets.BHalfYearBegin().startingMonth 1 ``` -------------------------------- ### Get HalfYearBegin with custom starting month Source: https://pandas.pydata.org/docs/reference/api/pandas.tseries.offsets.BHalfYearBegin.startingMonth.html Instantiate HalfYearBegin with a custom starting month and retrieve its value. This demonstrates how to define non-default half-year start points. ```python >>> pd.offsets.HalfYearBegin(startingMonth=3).startingMonth 3 ``` -------------------------------- ### Initialize DataFrame for clipping examples Source: https://pandas.pydata.org/docs/reference/api/pandas.Series.clip.html Sets up a sample DataFrame to demonstrate clipping operations. ```python >>> data = {"col_0": [9, -3, 0, -1, 5], "col_1": [-2, -7, 6, 8, -5]} >>> df = pd.DataFrame(data) >>> df col_0 col_1 0 9 -2 1 -3 -7 2 0 6 3 -1 8 4 5 -5 ``` -------------------------------- ### Setup for eval() Performance Comparison Source: https://pandas.pydata.org/docs/user_guide/enhancingperf.html Initializes DataFrames and Series for performance testing of pandas.eval(). ```python nrows, ncols = 20000, 100 df1, df2, df3, df4 = [pd.DataFrame(np.random.randn(nrows, ncols)) for _ in range(4)] ``` -------------------------------- ### Get Period Start Time - Python Source: https://pandas.pydata.org/docs/reference/api/pandas.Series.dt.start_time.html Retrieves the Timestamp representing the start of a pandas Period object. This is useful for time-series analysis where precise start times are needed. ```python import pandas as pd period = pd.Period('2012-1-1', freq='D') start_time = period.start_time print(start_time) ``` -------------------------------- ### Setup MultiIndex DataFrame Source: https://pandas.pydata.org/docs/whatsnew/v0.14.0.html Demonstrates creating a MultiIndex DataFrame using from_product and sorting indices for proper slicing performance. ```python import pandas as pd import numpy as np def mklbl(prefix, n): return ["%s%s" % (prefix, i) for i in range(n)] index = pd.MultiIndex.from_product([mklbl('A', 4), mklbl('B', 2), mklbl('C', 4), mklbl('D', 2)]) columns = pd.MultiIndex.from_tuples([('a', 'foo'), ('a', 'bar'), ('b', 'foo'), ('b', 'bah')], names=['lvl0', 'lvl1']) df = pd.DataFrame(np.arange(len(index) * len(columns)).reshape((len(index), len(columns))), index=index, columns=columns).sort_index().sort_index(axis=1) ``` -------------------------------- ### Get Starting Month for BHalfYearEnd Offset Source: https://pandas.pydata.org/docs/reference/api/pandas.tseries.offsets.HalfYearBegin.startingMonth.html Retrieves the starting month for the BHalfYearEnd offset. This indicates that half-years end in June. ```python >>> pd.offsets.BHalfYearEnd().startingMonth 6 ``` -------------------------------- ### Create DataFrame for examples Source: https://pandas.pydata.org/docs/reference/api/pandas.Series.shift.html Initializes a pandas DataFrame with a date range index and three columns for demonstration purposes. ```python df = pd.DataFrame( [[10, 13, 17], [20, 23, 27], [15, 18, 22], [30, 33, 37], [45, 48, 52]], columns=["Col1", "Col2", "Col3"], index=pd.date_range("2020-01-01", "2020-01-05"), ) df ``` -------------------------------- ### Get Business Hour Start Time - Python Source: https://pandas.pydata.org/docs/reference/api/pandas.tseries.offsets.CustomBusinessHour.start.html Retrieves the start time(s) of a business hour offset. This property returns a tuple of datetime.time objects representing the start times. ```python >>> pd.offsets.BusinessHour().start (datetime.time(9, 0),) ``` -------------------------------- ### Set and Get Starting Month for QuarterBegin Source: https://pandas.pydata.org/docs/reference/api/pandas.tseries.offsets.QuarterBegin.startingMonth.html Demonstrates how to set a custom starting month for a quarter begin offset and then retrieve its value. This allows for defining quarters that start in months other than the default. ```python >>> pd.offsets.QuarterBegin(startingMonth=1).startingMonth 1 ``` -------------------------------- ### Display HDFStore information Source: https://pandas.pydata.org/docs/reference/api/pandas.HDFStore.info.html This example demonstrates how to initialize an HDFStore, save multiple DataFrames to it, and print the summary information of the store using the info() method. ```python import pandas as pd df1 = pd.DataFrame([[1, 2], [3, 4]], columns=["A", "B"]) df2 = pd.DataFrame([[5, 6], [7, 8]], columns=["C", "D"]) store = pd.HDFStore("store.h5", "w") store.put("data1", df1) store.put("data2", df2) print(store.info()) store.close() ``` -------------------------------- ### Initialize DataFrame for JSON Export Source: https://pandas.pydata.org/docs/reference/api/pandas.Series.to_json.html Setup a sample DataFrame with index and columns for demonstration purposes. ```python >>> from json import loads, dumps >>> df = pd.DataFrame( ... [["a", "b"], ["c", "d"]], ... index=["row 1", "row 2"], ... columns=["col 1", "col 2"], ... ) ``` -------------------------------- ### Set and Get Starting Month for HalfYearBegin Offset Source: https://pandas.pydata.org/docs/reference/api/pandas.tseries.offsets.HalfYearBegin.startingMonth.html Demonstrates how to set a custom starting month for the HalfYearBegin offset and then retrieve its value. ```python >>> pd.offsets.HalfYearBegin(startingMonth=3).startingMonth 3 ``` -------------------------------- ### Create Example Series and DataFrame Source: https://pandas.pydata.org/docs/user_guide/basics.html Demonstrates the creation of a date range index, a Series with random data, and a DataFrame with random data, index, and columns. ```python index = pd.date_range("1/1/2000", periods=8) s = pd.Series(np.random.randn(5), index=["a", "b", "c", "d", "e"]) df = pd.DataFrame(np.random.randn(8, 3), index=index, columns=["A", "B", "C"]) ``` -------------------------------- ### Get BHalfYearEnd rule code Source: https://pandas.pydata.org/docs/reference/api/pandas.tseries.offsets.BHalfYearBegin.rule_code.html Instantiate a BHalfYearEnd offset with a specific starting month and access its rule_code property to get the string representation. ```python offset = pd.offsets.BHalfYearEnd(startingMonth=6) offset.rule_code ``` -------------------------------- ### Create DataFrame for examples Source: https://pandas.pydata.org/docs/reference/api/pandas.api.typing.SeriesGroupBy.mean.html Initializes a pandas DataFrame with sample data including NaN values for use in subsequent examples. ```python import pandas as pd import numpy as np df = pd.DataFrame( {"A": [1, 1, 2, 1, 2], "B": [np.nan, 2, 3, 4, 5], "C": [1, 2, 1, 1, 2]}, columns=["A", "B", "C"], ) ``` -------------------------------- ### Get Default Starting Month for QuarterEnd Source: https://pandas.pydata.org/docs/reference/api/pandas.tseries.offsets.QuarterBegin.startingMonth.html Retrieves the default starting month for a quarter end offset. The default is typically March (3). ```python >>> pd.offsets.QuarterEnd().startingMonth 3 ``` -------------------------------- ### Get Default Starting Month for BQuarterBegin Source: https://pandas.pydata.org/docs/reference/api/pandas.tseries.offsets.QuarterBegin.startingMonth.html Retrieves the default starting month for a business quarter begin offset. The default is typically March (3). ```python >>> pd.offsets.BQuarterBegin().startingMonth 3 ``` -------------------------------- ### Install Pandas with Clipboard Support Source: https://pandas.pydata.org/docs/getting_started/install.html Install Pandas with support for reading from and writing to the system clipboard. This requires PyQt4/PyQt5 or qtpy. ```bash pip install "pandas[clipboard]" ``` -------------------------------- ### GET /pandas/tseries/offsets/SemiMonthEnd/is_quarter_start Source: https://pandas.pydata.org/docs/reference/api/pandas.tseries.offsets.SemiMonthEnd.is_quarter_start.html Checks if a provided timestamp occurs on the start of a quarter. ```APIDOC ## GET /pandas/tseries/offsets/SemiMonthEnd/is_quarter_start ### Description Returns a boolean value indicating whether the provided timestamp occurs on the start of a quarter. ### Method GET ### Endpoint /pandas/tseries/offsets/SemiMonthEnd/is_quarter_start ### Parameters #### Path Parameters - **ts** (Timestamp) - Required - The timestamp to check against the quarter start criteria. ### Request Example { "ts": "2022-01-01" } ### Response #### Success Response (200) - **result** (boolean) - True if the timestamp is the start of a quarter, False otherwise. #### Response Example { "result": true } ``` -------------------------------- ### Create DataFrame for Styling Source: https://pandas.pydata.org/docs/reference/api/pandas.io.formats.style.Styler.background_gradient.html Initializes a pandas DataFrame with sample data for demonstration purposes. ```python df = pd.DataFrame( columns=["City", "Temp (c)", "Rain (mm)", "Wind (m/s)"], data=[ ["Stockholm", 21.6, 5.0, 3.2], ["Oslo", 22.4, 13.3, 3.1], ["Copenhagen", 24.5, 0.0, 6.7], ], ) ``` -------------------------------- ### GET /pandas/tseries/offsets/Tick/is_year_start Source: https://pandas.pydata.org/docs/reference/api/pandas.tseries.offsets.Tick.is_year_start.html Checks if a specific timestamp corresponds to the start of a year. ```APIDOC ## GET /pandas/tseries/offsets/Tick/is_year_start ### Description Return a boolean value indicating whether the provided timestamp occurs on the start of the year. ### Method GET ### Endpoint /pandas/tseries/offsets/Tick/is_year_start ### Parameters #### Path Parameters - **ts** (Timestamp) - Required - The timestamp to check. ### Request Example { "ts": "2022-01-01" } ### Response #### Success Response (200) - **result** (boolean) - Returns True if the timestamp is January 1st, otherwise False. #### Response Example { "result": true } ``` -------------------------------- ### Initialize DataFrame Source: https://pandas.pydata.org/docs/user_guide/cookbook.html Demonstrates how to create a pandas DataFrame from a dictionary. ```python df = pd.DataFrame( {"AAA": [4, 5, 6, 7], "BBB": [10, 20, 30, 40], "CCC": [100, 50, -30, -50]} ) ``` -------------------------------- ### Initialize DataFrame for ffill examples Source: https://pandas.pydata.org/docs/reference/api/pandas.Series.ffill.html Create a sample DataFrame with NaN values to demonstrate forward filling behavior. ```python >>> df = pd.DataFrame( ... [ ... [np.nan, 2, np.nan, 0], ... [3, 4, np.nan, 1], ... [np.nan, np.nan, np.nan, np.nan], ... [np.nan, 3, np.nan, 4], ... ], ... columns=list("ABCD"), ... ) >>> df A B C D 0 NaN 2.0 NaN 0.0 1 3.0 4.0 NaN 1.0 2 NaN NaN NaN NaN 3 NaN 3.0 NaN 4.0 ``` -------------------------------- ### GET /pandas/tseries/offsets/Micro/is_month_start Source: https://pandas.pydata.org/docs/reference/api/pandas.tseries.offsets.Micro.is_month_start.html Determines if a provided timestamp occurs on the start of a month. ```APIDOC ## GET /pandas/tseries/offsets/Micro/is_month_start ### Description Returns a boolean value indicating whether the provided timestamp occurs on the first day of the month. ### Method GET ### Endpoint /pandas/tseries/offsets/Micro/is_month_start ### Parameters #### Path Parameters - **ts** (Timestamp) - Required - The timestamp object to evaluate. ### Request Example { "ts": "2022-01-01" } ### Response #### Success Response (200) - **result** (boolean) - Returns True if the timestamp is the first day of the month, otherwise False. #### Response Example { "result": true } ``` -------------------------------- ### Install Pandas with Compression Support Source: https://pandas.pydata.org/docs/getting_started/install.html Install Pandas with support for additional compression libraries, such as Zstandard. ```bash pip install "pandas[compression]" ``` -------------------------------- ### GET /pandas/tseries/offsets/DateOffset/is_month_start Source: https://pandas.pydata.org/docs/reference/api/pandas.tseries.offsets.DateOffset.is_month_start.html Checks if a given timestamp occurs on the start of a month. ```APIDOC ## GET /pandas/tseries/offsets/DateOffset/is_month_start ### Description Determines if a given timestamp falls on the first day of a month, considering the frequency of the offset. ### Method GET ### Endpoint /pandas/tseries/offsets/DateOffset/is_month_start ### Parameters #### Query Parameters - **ts** (Timestamp) - Required - The timestamp to check. ### Request Example { "ts": "2022-01-01" } ### Response #### Success Response (200) - **result** (boolean) - Returns True if the timestamp is the first day of the month, False otherwise. #### Response Example { "result": true } ``` -------------------------------- ### Registering Pandas Plotting Backend via Entry Points (Python Setup) Source: https://pandas.pydata.org/docs/development/extending.html Illustrates how a third-party library can register its plotting backend with pandas using Python's `entry_points` mechanism in `setup.py`. This makes the backend discoverable by pandas. ```python # in setup.py # setup( # ..., # entry_points={ # "pandas_plotting_backends": [ # "matplotlib = pandas:plotting._matplotlib", # ], # }, # ) ``` -------------------------------- ### GET /pandas/tseries/offsets/BusinessMonthEnd/is_month_start Source: https://pandas.pydata.org/docs/reference/api/pandas.tseries.offsets.BusinessMonthEnd.is_month_start.html Checks if a provided timestamp occurs on the start of a month. ```APIDOC ## GET /pandas/tseries/offsets/BusinessMonthEnd/is_month_start ### Description Determines if a given timestamp falls on the first day of a month, considering the frequency of the offset. ### Method GET ### Endpoint /pandas/tseries/offsets/BusinessMonthEnd/is_month_start ### Parameters #### Query Parameters - **ts** (Timestamp) - Required - The timestamp to check. ### Request Example { "ts": "2022-01-01" } ### Response #### Success Response (200) - **result** (boolean) - Returns true if the timestamp is the start of the month, false otherwise. #### Response Example { "result": true } ``` -------------------------------- ### GET /pandas/tseries/offsets/BusinessDay/is_month_start Source: https://pandas.pydata.org/docs/reference/api/pandas.tseries.offsets.BusinessDay.is_month_start.html Checks if a given timestamp occurs on the start of a month. ```APIDOC ## GET /pandas/tseries/offsets/BusinessDay/is_month_start ### Description Returns a boolean indicating whether a provided timestamp occurs on the first day of the month. ### Method GET ### Endpoint /pandas/tseries/offsets/BusinessDay/is_month_start ### Parameters #### Query Parameters - **ts** (Timestamp) - Required - The timestamp to evaluate against the month start criteria. ### Request Example { "ts": "2022-01-01" } ### Response #### Success Response (200) - **result** (boolean) - True if the timestamp is the first day of the month, False otherwise. #### Response Example { "result": true } ``` -------------------------------- ### Pandas Documentation Example Patterns Source: https://pandas.pydata.org/docs/development/contributing_docstring.html Examples demonstrating standard pandas documentation practices, including method definitions, docstring formatting, and the use of keyword arguments for clarity. ```python class Series: def mean(self): """ Compute the mean of the input. Examples -------- >>> ser = pd.Series([1, 2, 3]) >>> ser.mean() 2 """ pass def fillna(self, value): """ Replace missing values by ``value``. Examples -------- >>> ser = pd.Series([1, np.nan, 3]) >>> ser.fillna(value=0) [1, 0, 3] """ pass def groupby_mean(self): """ Group by index and return mean. Examples -------- >>> ser = pd.Series([380., 370., 24., 26], ... name='max_speed', ... index=['falcon', 'falcon', 'parrot', 'parrot']) >>> ser.groupby_mean() """ pass ``` -------------------------------- ### GET BYearEnd.is_year_start Source: https://pandas.pydata.org/docs/reference/api/pandas.tseries.offsets.BYearEnd.is_year_start.html Checks if a provided timestamp occurs on the start of a year. ```APIDOC ## METHOD BYearEnd.is_year_start ### Description Returns a boolean value indicating whether the provided timestamp occurs on the start of a year. ### Method N/A (Class Method) ### Endpoint pandas.tseries.offsets.BYearEnd.is_year_start(ts) ### Parameters #### Path Parameters - **ts** (Timestamp) - Required - The timestamp to check. ### Request Example ```python import pandas as pd from pandas.tseries.offsets import BYearEnd ts = pd.Timestamp(2022, 1, 1) offset = BYearEnd() offset.is_year_start(ts) ``` ### Response #### Success Response (200) - **result** (boolean) - True if the timestamp is at the start of the year, False otherwise. #### Response Example ```json True ``` ``` -------------------------------- ### Create DataFrame for Examples Source: https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.nlargest.html This snippet demonstrates how to create a pandas DataFrame with sample data including population, GDP, and alpha-2 codes, which will be used in subsequent examples. ```python import pandas as pd df = pd.DataFrame({ "population": [ 59000000, 65000000, 434000, 434000, 434000, 337000, 11300, 11300, 11300, ], "GDP": [1937894, 2583560, 12011, 4520, 12128, 17036, 182, 38, 311], "alpha-2": ["IT", "FR", "MT", "MV", "BN", "IS", "NR", "TV", "AI"], }, index=[ "Italy", "France", "Malta", "Maldives", "Brunei", "Iceland", "Nauru", "Tuvalu", "Anguilla", ], ) print(df) ``` -------------------------------- ### GET QuarterEnd.startingMonth Source: https://pandas.pydata.org/docs/reference/api/pandas.tseries.offsets.QuarterEnd.startingMonth.html Retrieves the starting month configuration for a QuarterEnd offset instance. ```APIDOC ## GET QuarterEnd.startingMonth ### Description Returns the month of the year from which quarters start for the QuarterEnd offset instance. This value determines the quarterly cycle (e.g., 1 for Jan/Apr/Jul/Oct). ### Method GET ### Endpoint pandas.tseries.offsets.QuarterEnd.startingMonth ### Parameters #### Path Parameters - None ### Request Example N/A (Property access) ### Response #### Success Response (200) - **startingMonth** (int) - The month integer (1-12) representing the start of the quarter. #### Response Example ```python >>> pd.offsets.QuarterEnd(startingMonth=1).startingMonth 1 ``` ``` -------------------------------- ### Create a DataFrame Source: https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.clip.html Initializes a pandas DataFrame for demonstration purposes. ```python import pandas as pd data = {"col_0": [9, -3, 0, -1, 5], "col_1": [-2, -7, 6, 8, -5]} df = pd.DataFrame(data) print(df) ``` -------------------------------- ### DataFrame Initialization for Eval Example Source: https://pandas.pydata.org/docs/whatsnew/v0.18.0.html Initializes a DataFrame with columns 'a' and 'b' for demonstrating the eval method. ```python In [86]: df = pd.DataFrame({'a': np.linspace(0, 10, 5), 'b': range(5)}) In [87]: df Out[87]: a b 0 0.0 0 1 2.5 1 2 5.0 2 3 7.5 3 4 10.0 4 ``` -------------------------------- ### GET /pandas/tseries/offsets/BQuarterEnd/startingMonth Source: https://pandas.pydata.org/docs/reference/api/pandas.tseries.offsets.BQuarterEnd.startingMonth.html Retrieves the starting month of the year for the BQuarterEnd offset instance. ```APIDOC ## GET /pandas/tseries/offsets/BQuarterEnd/startingMonth ### Description Returns the month of the year from which quarters start for the BQuarterEnd offset. This value determines the quarterly period cycle. ### Method GET ### Endpoint pandas.tseries.offsets.BQuarterEnd.startingMonth ### Parameters #### Path Parameters - None #### Query Parameters - None ### Request Example N/A (Property access) ### Response #### Success Response (200) - **startingMonth** (int) - The month index (1-12) representing the start of the quarter. #### Response Example ```python >>> pd.offsets.BQuarterEnd().startingMonth 3 ``` ``` -------------------------------- ### GET BHalfYearEnd.startingMonth Source: https://pandas.pydata.org/docs/reference/api/pandas.tseries.offsets.BHalfYearEnd.startingMonth.html Retrieves the starting month configuration for the BHalfYearEnd offset object. ```APIDOC ## GET BHalfYearEnd.startingMonth ### Description Returns the month of the year from which half-years start for the BHalfYearEnd offset instance. ### Method GET ### Endpoint pandas.tseries.offsets.BHalfYearEnd.startingMonth ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - None ### Request Example N/A (Property access) ### Response #### Success Response (200) - **startingMonth** (int) - The month index (1-12) representing the start of the half-year period. #### Response Example ```python >>> pd.offsets.BHalfYearEnd().startingMonth 6 ``` ``` -------------------------------- ### Describe a specific pandas option Source: https://pandas.pydata.org/docs/reference/api/pandas.describe_option.html This example demonstrates how to use describe_option to retrieve the documentation for a specific configuration key, such as display.max_columns. It prints the description to the console by default. ```python import pandas as pd # Print the description for a specific option pd.describe_option("display.max_columns") ``` -------------------------------- ### GET /pandas/tseries/offsets/BHalfYearBegin/is_quarter_start Source: https://pandas.pydata.org/docs/reference/api/pandas.tseries.offsets.BHalfYearBegin.is_quarter_start.html Checks whether a provided timestamp occurs on the start of a quarter. ```APIDOC ## GET /pandas/tseries/offsets/BHalfYearBegin/is_quarter_start ### Description Returns a boolean value indicating whether the specified timestamp occurs on the start of a quarter. ### Method GET ### Endpoint /pandas/tseries/offsets/BHalfYearBegin/is_quarter_start ### Parameters #### Path Parameters - **ts** (Timestamp) - Required - The timestamp to check against the quarter start criteria. ### Request Example { "ts": "2022-01-01" } ### Response #### Success Response (200) - **result** (boolean) - True if the timestamp is the start of a quarter, False otherwise. #### Response Example { "result": true } ``` -------------------------------- ### See Also Section Example Source: https://pandas.pydata.org/docs/development/contributing_docstring.html Example of how to structure the 'See Also' section in pandas documentation, listing related functions with brief descriptions. ```APIDOC ## See Also Series.tail : Return the last 5 elements of the Series. Series.iloc : Return a slice of the elements in the Series, which can also be used to return the first or last n. ``` -------------------------------- ### GET Period.start_time Source: https://pandas.pydata.org/docs/reference/api/pandas.Period.start_time.html Retrieves the start Timestamp for a given pandas Period object. ```APIDOC ## GET Period.start_time ### Description Returns the Timestamp representing the start of the period defined by the Period object. ### Method GET (Property Access) ### Endpoint Period.start_time ### Parameters None ### Request Example ```python import pandas as pd period = pd.Period('2012-1-1', freq='D') print(period.start_time) ``` ### Response #### Success Response (200) - **Timestamp** (object) - The Timestamp object corresponding to the start of the period. #### Response Example ```python Timestamp('2012-01-01 00:00:00') ``` ``` -------------------------------- ### Check if Timestamp is Quarter Start with FY5253 Source: https://pandas.pydata.org/docs/reference/api/pandas.tseries.offsets.FY5253.is_quarter_start.html Demonstrates how to use the is_quarter_start method on a pandas Timestamp. This example initializes a timestamp and checks its alignment with the fiscal quarter start. ```python import pandas as pd from pandas.tseries.offsets import FY5253 ts = pd.Timestamp(2022, 1, 1) freq = FY5253(startingMonth=1) print(freq.is_quarter_start(ts)) ``` -------------------------------- ### Initialize HDFStore Source: https://pandas.pydata.org/docs/user_guide/io.html Opens an HDF5 file for storing pandas objects. Ensure PyTables is installed. ```python import pandas as pd import numpy as np store = pd.HDFStore("store.h5") print(store) ``` -------------------------------- ### Example: Hour Offset Nanoseconds (Python) Source: https://pandas.pydata.org/docs/reference/api/pandas.tseries.offsets.BusinessMonthBegin.nanos.html Demonstrates how to get the total number of nanoseconds for the Hour offset in pandas. This is an example of a fixed frequency where the .nanos attribute returns a valid integer. ```python import pandas as pd # Get nanoseconds for 1 hour hour_nanos = pd.offsets.Hour(n=1).nanos print(f"Nanoseconds in one hour: {hour_nanos}") ``` -------------------------------- ### Create a Pandas DataFrame Source: https://pandas.pydata.org/docs/user_guide/10min.html Initializes a sample Pandas DataFrame with columns 'A', 'B', 'C', and 'D' for demonstrating grouping operations. This setup is required before performing any group by actions. ```python import pandas as pd import numpy as np df = pd.DataFrame( { "A": ["foo", "bar", "foo", "bar", "foo", "bar", "foo", "foo"], "B": ["one", "one", "two", "three", "two", "two", "one", "three"], "C": np.random.randn(8), "D": np.random.randn(8), } ) ``` -------------------------------- ### Check if Timestamp is Month Start with pandas Offset Source: https://pandas.pydata.org/docs/reference/api/pandas.tseries.offsets.BQuarterEnd.is_month_start.html This example demonstrates how to use the is_month_start method on a pandas frequency offset object. It checks if a specific timestamp corresponds to the start of a month. ```python import pandas as pd ts = pd.Timestamp(2022, 1, 1) freq = pd.offsets.Hour(5) result = freq.is_month_start(ts) print(result) ``` -------------------------------- ### Create a DataFrame for ffill examples Source: https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.ffill.html Initializes a pandas DataFrame with NaN values for demonstrating the ffill method. ```python import pandas as pd import numpy as np df = pd.DataFrame( [ [np.nan, 2, np.nan, 0], [3, 4, np.nan, 1], [np.nan, np.nan, np.nan, np.nan], [np.nan, 3, np.nan, 4], ], columns=list("ABCD"), ) df ``` -------------------------------- ### Retrieve HDFStore keys Source: https://pandas.pydata.org/docs/reference/api/pandas.HDFStore.keys.html This example demonstrates how to initialize an HDFStore, save a DataFrame, and retrieve the list of keys present in the store. It highlights the use of the keys() method to inspect the contents of the HDF5 file. ```python import pandas as pd df = pd.DataFrame([[1, 2], [3, 4]], columns=["A", "B"]) store = pd.HDFStore("store.h5", "w") store.put("data", df) print(store.keys()) store.close() ``` -------------------------------- ### Create a DataFrame Source: https://pandas.pydata.org/docs/reference/api/pandas.melt.html Initializes a sample DataFrame for demonstrating the melt function. ```python df = pd.DataFrame( { "A": {0: "a", 1: "b", 2: "c"}, "B": {0: 1, 1: 3, 2: 5}, "C": {0: 2, 1: 4, 2: 6}, } ) df ``` -------------------------------- ### Get Period Start Time with pandas Source: https://pandas.pydata.org/docs/reference/api/pandas.PeriodIndex.start_time.html Demonstrates how to create a pandas Period object and access its `start_time` property to get the Timestamp for the beginning of the period. It also shows the `end_time` property for comparison. ```python >>> period = pd.Period('2012-1-1', freq='D') >>> period Period('2012-01-01', 'D') >>> period.start_time Timestamp('2012-01-01 00:00:00') >>> period.end_time Timestamp('2012-01-01 23:59:59.999999') ``` -------------------------------- ### Check if timestamp is quarter start using BusinessMonthBegin Source: https://pandas.pydata.org/docs/reference/api/pandas.tseries.offsets.BusinessMonthBegin.is_quarter_start.html This example demonstrates how to instantiate a pandas Timestamp and check if it represents the start of a quarter using the is_quarter_start method. It returns a boolean value indicating the result. ```python import pandas as pd from pandas.tseries.offsets import BusinessMonthBegin ts = pd.Timestamp(2022, 1, 1) freq = BusinessMonthBegin() result = freq.is_quarter_start(ts) print(result) ``` -------------------------------- ### Install ASV Benchmark Tool Source: https://pandas.pydata.org/docs/development/contributing_codebase.html Installs the Airspeed Velocity (ASV) tool from the official GitHub repository using pip. This is a prerequisite for running the pandas performance test suite. ```bash pip install git+https://github.com/airspeed-velocity/asv ``` -------------------------------- ### Check if Timestamp is Month Start with pandas Source: https://pandas.pydata.org/docs/reference/api/pandas.tseries.offsets.BusinessDay.is_month_start.html This example demonstrates how to use the is_month_start method on a pandas offset object. It creates a Timestamp and an offset frequency, then evaluates whether the timestamp represents the start of the month. ```python import pandas as pd ts = pd.Timestamp(2022, 1, 1) freq = pd.offsets.Hour(5) result = freq.is_month_start(ts) print(result) # Output: True ``` -------------------------------- ### Create DataFrame and Series for Orient Options Source: https://pandas.pydata.org/docs/user_guide/io.html Sets up a sample DataFrame and Series used to illustrate different JSON orientation options. ```python In [221]: dfjo = pd.DataFrame( .....: dict(A=range(1, 4), B=range(4, 7), C=range(7, 10)), .....: columns=list("ABC"), .....: index=list("xyz"), .....: ) .....: In [222]: dfjo Out[222]: A B C x 1 4 7 y 2 5 8 z 3 6 9 In [223]: sjo = pd.Series(dict(x=15, y=16, z=17), name="D") In [224]: sjo Out[224]: x 15 y 16 z 17 Name: D, dtype: int64 ``` -------------------------------- ### Retrieve Data from HDFStore Source: https://pandas.pydata.org/docs/reference/api/pandas.HDFStore.get.html This example demonstrates how to create an HDFStore, store a DataFrame, retrieve it using the get method, and close the store. It requires an existing HDF5 file or creates a new one in write mode. ```python import pandas as pd df = pd.DataFrame([[1, 2], [3, 4]], columns=["A", "B"]) store = pd.HDFStore("store.h5", "w") store.put("data", df) # Retrieve the stored DataFrame result = store.get("data") store.close() ``` -------------------------------- ### Create a custom Styler subclass with from_custom_template Source: https://pandas.pydata.org/docs/reference/api/pandas.io.formats.style.Styler.from_custom_template.html This example demonstrates how to initialize a custom Styler class by providing a search path and a template filename. The resulting class can then be used to style a pandas DataFrame. ```python from pandas.io.formats.style import Styler import pandas as pd # Create a custom Styler subclass EasyStyler = Styler.from_custom_template( "path/to/template", "template.tpl", ) # Apply the custom styler to a DataFrame df = pd.DataFrame({"A": [1, 2]}) EasyStyler(df) ``` -------------------------------- ### GET Series.str.startswith Source: https://pandas.pydata.org/docs/reference/api/pandas.Series.str.startswith.html Tests if the start of each string element in a Series matches a given pattern or tuple of patterns. ```APIDOC ## GET Series.str.startswith ### Description Test if the start of each string element matches a pattern. This method is equivalent to the Python standard library str.startswith() method but applied to a pandas Series. ### Method GET ### Endpoint Series.str.startswith(pat, na=) ### Parameters #### Path Parameters - **pat** (str or tuple[str, ...]) - Required - Character sequence or tuple of strings to match. Regular expressions are not accepted. #### Query Parameters - **na** (scalar) - Optional - Object shown if element tested is not a string. Default depends on dtype (False for 'str', np.nan for object, pandas.NA for StringDtype). ### Request Example { "pat": "b" } ### Response #### Success Response (200) - **Series/Index of bool** (bool) - A Series of booleans indicating whether the pattern matches the start of each string element. #### Response Example { "0": true, "1": false, "2": false, "3": false } ``` -------------------------------- ### GET /pandas/bdate_range Source: https://pandas.pydata.org/docs/reference/api/pandas.bdate_range.html Generates a DatetimeIndex with business day frequency based on provided start, end, or period constraints. ```APIDOC ## GET /pandas/bdate_range ### Description Return a fixed frequency DatetimeIndex with business day as the default. Of the four parameters (start, end, periods, freq), exactly three must be specified. ### Method GET ### Endpoint pandas.bdate_range ### Parameters #### Query Parameters - **start** (str/datetime) - Optional - Left bound for generating dates. - **end** (str/datetime) - Optional - Right bound for generating dates. - **periods** (int) - Optional - Number of periods to generate. - **freq** (str/Timedelta) - Optional - Frequency string, default 'B' (business daily). - **tz** (str) - Optional - Time zone name. - **normalize** (bool) - Optional - Normalize start/end dates to midnight. - **weekmask** (str) - Optional - Weekmask of valid business days. - **holidays** (list) - Optional - Dates to exclude. - **inclusive** (str) - Optional - Boundary inclusion ('both', 'neither', 'left', 'right'). ### Request Example { "start": "2018-01-01", "end": "2018-01-08", "freq": "B" } ### Response #### Success Response (200) - **DatetimeIndex** (object) - A fixed frequency DatetimeIndex object. #### Response Example { "result": ["2018-01-01", "2018-01-02", "2018-01-03", "2018-01-04", "2018-01-05", "2018-01-08"], "freq": "B" } ```