### Create a Sample FrameGO Source: https://github.com/static-frame/static-frame/blob/master/doc/source/demo_sf08.ipynb Creates a sample FrameGO object for demonstration purposes. This is a basic setup for subsequent examples. ```python # A sample Frame f = ff.parse('s(4,3)|v(float,float,int)|c(I,str)').to_frame_go() f ``` -------------------------------- ### IndexYearMonthGO from_date_range() example Source: https://github.com/static-frame/static-frame/blob/master/doc/source/examples.txt Demonstrates creating an IndexYearMonthGO from a date range specified by start and end dates. ```python >>> sf.IndexYearMonthGO.from_date_range('2021-12-30', '2022-01-02') 2021-12 2022-01 ``` -------------------------------- ### IndexMicrosecond min() example Source: https://github.com/static-frame/static-frame/blob/master/doc/source/examples.txt Shows how to get the minimum value from an IndexMicrosecond object using the min() method. ```python >>> ix = sf.IndexMicrosecond(('1517-04-01', '1517-12-31', '1517-06-30')) >>> ix 1517-04-01T00:00:00.000000 1517-12-31T00:00:00.000000 1517-06-30T00:00:00.000000 >>> ix.min() 1517-04-01T00:00:00.000000 ``` -------------------------------- ### IndexNanosecond.via_str.startswith() Example Source: https://github.com/static-frame/static-frame/blob/master/doc/source/examples.txt Checks if each string in an IndexNanosecond starts with a specified prefix. The example uses 'X' as the prefix, which is not present at the start of the dates. ```python >>> ix = sf.IndexNanosecond(('1789-05-05', '1789-12-31', '1799-11-09')) >>> ix 1789-05-05T00:00:00.000000000 1789-12-31T00:00:00.000000000 1799-11-09T00:00:00.000000000 >>> ix.via_str.startswith('X') [False False False] ``` -------------------------------- ### IndexHourGO via_str startswith() Example Source: https://github.com/static-frame/static-frame/blob/master/doc/source/examples.txt Checks if each string starts with a specified prefix. ```python >>> ix = sf.IndexHourGO(('1517-04-01', '1517-12-31', '1517-06-30')) >>> ix.via_str.startswith('X') [False False False] ``` -------------------------------- ### Create Example Frame Source: https://github.com/static-frame/static-frame/blob/master/doc/source/articles/serialize.txt This snippet demonstrates the creation of an example StaticFrame Frame with hierarchical indexes and multiple columns, which can then be used for serialization examples. ```python import static as sf from functools import partial f = sf.Frame.from_items((("data", "A"), (5, 9, 3)), (("data", "B"), (4, 1, 6)), (("data", "C"), (7, 8, 2)), (("valid", "*"), (False, True, True))), name='p', index=sf.IndexHierarchy.from_labels((('2012-03', 'x'), ('2012-03', 'y'), ('2012-04', 'x')), index_constructors=(sf.IndexYearMonth, sf.Index), name='r'), columns_constructor=partial(sf.IndexHierarchy.from_labels, name='q')) ``` -------------------------------- ### IndexMicrosecond tail() example Source: https://github.com/static-frame/static-frame/blob/master/doc/source/examples.txt Shows an example of using the tail() method with a string argument, which results in a TypeError. ```python >>> ix = sf.IndexMicrosecond(('1517-04-01', '1517-12-31', '1517-06-30')) >>> ix 1517-04-01T00:00:00.000000 1517-12-31T00:00:00.000000 1517-06-30T00:00:00.000000 >>> ix.tail("1517-12") TypeError("bad operand type for unary -: 'str'") ``` -------------------------------- ### SeriesHE startswith() Example Source: https://github.com/static-frame/static-frame/blob/master/doc/source/examples.txt Checks if string elements in a SeriesHE start with a specified prefix. Returns a boolean Series indicating the result for each element. ```python >>> s = sf.SeriesHE(('qrs ', 'XYZ', '123', ' wX '), index=('a', 'b', 'c', 'd')) >>> s a qrs b XYZ c 123 d wX < < >>> s.via_str.startswith('X') a False b True c False d False < ``` -------------------------------- ### Install StaticFrame via pip Source: https://github.com/static-frame/static-frame/blob/master/README.rst Install StaticFrame using pip. Pre-built wheels are available for all supported Python versions and platforms. ```bash pip install static-frame ``` -------------------------------- ### Set Up Development Environment Source: https://github.com/static-frame/static-frame/blob/master/CONTRIBUTING.rst Create and activate a virtual environment, then install development requirements for Python 3.14. ```bash cd static-frame python3 -m venv .env-sf source .env-sf/bin/activate pip install -r requirements-dev-3_14.txt ``` -------------------------------- ### IndexNanosecond.via_re.match() Example Source: https://github.com/static-frame/static-frame/blob/master/doc/source/examples.txt Attempts to match a regular expression pattern at the beginning of each string in an IndexNanosecond. The example uses '[X123]' as the pattern, which matches the start of the date strings. ```python >>> ix = sf.IndexNanosecond(('1789-05-05', '1789-12-31', '1799-11-09')) >>> ix 1789-05-05T00:00:00.000000000 1789-12-31T00:00:00.000000000 1799-11-09T00:00:00.000000000 >>> ix.via_re('[X123]').match() [ True True True] ``` -------------------------------- ### IndexMinuteGO fillna() Example Source: https://github.com/static-frame/static-frame/blob/master/doc/source/examples.txt Fills NaN (Not a Number) values in an IndexMinuteGO object with a specified value. This example fills NaT with the epoch start date (0). ```python >>> ix = sf.IndexMinuteGO(('1620-09-16', 'NaT', '1620-11-21')) >>> ix 1620-09-16T00:00 NaT 1620-11-21T00:00 >>> ix.fillna(0) 1620-09-16T00:00 1970-01-01T00:00 1620-11-21T00:00 ) ``` -------------------------------- ### IndexYearMonthGO __init__() example Source: https://github.com/static-frame/static-frame/blob/master/doc/source/examples.txt Shows the initialization of an IndexYearMonthGO object from a list of year-month strings. ```python >>> sf.IndexYearMonthGO(('1517-04', '1517-12', '1517-06')) 1517-04 1517-12 1517-06 ``` -------------------------------- ### Initialize IndexMinuteGO Source: https://github.com/static-frame/static-frame/blob/master/doc/source/examples.txt Example of initializing an IndexMinuteGO object with a list of date strings. ```python >>> sf.IndexMinuteGO(('1517-04-01', '1517-12', '1517-06-30')) 1517-04-01T00:00 1517-12-01T00:00 1517-06-30T00:00 ``` -------------------------------- ### Get Name of IndexMillisecond Source: https://github.com/static-frame/static-frame/blob/master/doc/source/examples.txt Retrieve the name of the IndexMillisecond. This example shows it is unset. ```python >>> ix = sf.IndexMillisecond(('1517-04-01', '1517-12-31', '1517-06-30')) >>> ix.name ``` -------------------------------- ### IndexMillisecondGO zfill() example Source: https://github.com/static-frame/static-frame/blob/master/doc/source/examples.txt Demonstrates the zfill method on IndexMillisecondGO objects. This method pads each string with leading zeros to a specified width. ```python >>> ix = sf.IndexMillisecondGO(('1517-04-01', '1517-12-31', '1517-06-30')) >>> ix 1517-04-01T00:00:00.000 1517-12-31T00:00:00.000 1517-06-30T00:00:00.000 >>> ix.via_str.zfill(8) ['1517-04-01T00:00:00.000' '1517-12-31T00:00:00.000' '1517-06-30T00:00:00.000'] ``` -------------------------------- ### Iterate and get keys using __iter__ with reduction Source: https://github.com/static-frame/static-frame/blob/master/doc/source/examples.txt Similar to getting keys, this example uses the __iter__ method after applying a reduction to retrieve the keys from the grouped iteration. ```python >>> f = sf.Frame.from_fields(((11, 4, 10, 2), (0, 8, 3, 8), (0, 1, 0, 1)), columns=('a', 'b', 'c'), name='x') >>> f a b c < 0 11 0 0 1 4 8 1 2 10 3 0 3 2 8 1 >>> tuple(f.iter_group_array_items('c').reduce.from_label_pair_map({('b', 'b-min'): lambda l, a: np.min(a), ('b', 'b-max'): lambda l, a: np.max(a)}).__iter__()) ``` -------------------------------- ### Create FrameGO with __init__ Source: https://github.com/static-frame/static-frame/blob/master/doc/source/examples.txt Demonstrates the basic initialization of a FrameGO object using NumPy arrays for data and specified index and columns. ```python import static_frame as sf import numpy as np sf.FrameGO(np.arange(6).reshape(3,2), index=('p', 'q', 'r'), columns=('a', 'b'), name='x') ``` -------------------------------- ### IndexSecondGO sample() Example Source: https://github.com/static-frame/static-frame/blob/master/doc/source/examples.txt Shows how to randomly sample elements from an IndexSecondGO. A seed can be provided for reproducibility. ```python >>> ix = sf.IndexSecondGO(('1517-04-01', '1517-12-31', '1517-06-30')) >>> ix 1517-04-01T00:00:00 1517-12-31T00:00:00 1517-06-30T00:00:00 >>> ix.sample(2, seed=0) 1517-12-31T00:00:00 1517-06-30T00:00:00 ``` -------------------------------- ### IndexYear.via_str.startswith() Example Source: https://github.com/static-frame/static-frame/blob/master/doc/source/examples.txt Checks if the string representation of each year in the IndexYear starts with a specified prefix. ```python >>> ix = sf.IndexYear(('1517', '1520', '1518')) >>> ix.via_str.startswith('X') [False False False] ``` -------------------------------- ### IndexMillisecondGO startswith() example Source: https://github.com/static-frame/static-frame/blob/master/doc/source/examples.txt Demonstrates the startswith method on IndexMillisecondGO objects. This method checks if each string begins with a specified prefix. ```python >>> ix = sf.IndexMillisecondGO(('1517-04-01', '1517-12-31', '1517-06-30')) >>> ix 1517-04-01T00:00:00.000 1517-12-31T00:00:00.000 1517-06-30T00:00:00.000 >>> ix.via_str.startswith('X') [False False False] ``` -------------------------------- ### IndexYearMonth startswith() Example Source: https://github.com/static-frame/static-frame/blob/master/doc/source/examples.txt Checks if string representations of IndexYearMonth values start with a specified prefix. ```python >>> ix = sf.IndexYearMonth(('1517-04', '1517-12', '1517-06')) >>> ix 1517-04 1517-12 1517-06 >>> ix.via_str.startswith('X') [False False False] ``` -------------------------------- ### IndexGO.via_str.rsplit() Example Source: https://github.com/static-frame/static-frame/blob/master/doc/source/examples.txt Splits each string in an IndexGO by a separator, starting from the right. The number of splits is not limited. ```python >>> ix = sf.IndexGO(('qrs ', 'XYZ', '123', ' wX ')) >>> ix.via_str.rsplit('X') ``` -------------------------------- ### Initialize IndexMicrosecondGO Source: https://github.com/static-frame/static-frame/blob/master/doc/source/examples.txt Demonstrates the initialization of an IndexMicrosecondGO object with a list of datetime-like strings. This is the primary way to create an instance of this index type. ```python >>> ix = sf.IndexMicrosecondGO(('1620-09-16', 'NaT', '1620-11-21')) >>> ix 1620-09-16T00:00:00.000000 NaT 1620-11-21T00:00:00.000000 ``` -------------------------------- ### Install StaticFrame with Optional Dependencies Source: https://github.com/static-frame/static-frame/blob/master/README.rst Install StaticFrame with optional dependencies for full support of input and output formats like XLSX and HDF5. ```bash pip install static-frame [extras] ``` -------------------------------- ### IndexMillisecondGO split() example Source: https://github.com/static-frame/static-frame/blob/master/doc/source/examples.txt Demonstrates the split method on IndexMillisecondGO objects. This method splits each string by the specified separator. ```python >>> ix = sf.IndexMillisecondGO(('1517-04-01', '1517-12-31', '1517-06-30')) >>> ix 1517-04-01T00:00:00.000 1517-12-31T00:00:00.000 1517-06-30T00:00:00.000 >>> ix.via_str.split('X') [('1517-04-01T00:00:00.000',) ('1517-12-31T00:00:00.000',) ('1517-06-30T00:00:00.000',)] ``` -------------------------------- ### IndexSecondGO unique() Example Source: https://github.com/static-frame/static-frame/blob/master/doc/source/examples.txt Demonstrates how to get the unique values from an IndexSecondGO. NaT is included as a unique value. ```python >>> ix = sf.IndexSecondGO(('1620-09-16', 'NaT', '1620-11-21')) >>> ix 1620-09-16T00:00:00 NaT 1620-11-21T00:00:00 >>> ix.unique() ['1620-09-16T00:00:00' 'NaT' '1620-11-21T00:00:00'] ``` -------------------------------- ### IndexMicrosecond Initialization Source: https://github.com/static-frame/static-frame/blob/master/doc/source/examples.txt Demonstrates the basic initialization of an IndexMicrosecond with a list of date strings. The output shows the index with microsecond precision. ```python >>> sf.IndexMicrosecond(('1517-04-01', '1517-12-31', '1517-06-30')) 1517-04-01T00:00:00.000000 1517-12-31T00:00:00.000000 1517-06-30T00:00:00.000000 ``` -------------------------------- ### IndexGO.via_str.zfill() Example Source: https://github.com/static-frame/static-frame/blob/master/doc/source/examples.txt Pads each string in an IndexGO on the left with zeros to a specified width. ```python >>> ix = sf.IndexGO(('qrs ', 'XYZ', '123', ' wX ')) >>> ix.via_str.zfill(8) ``` -------------------------------- ### IndexSecondGO label_widths_at_depth() example Source: https://github.com/static-frame/static-frame/blob/master/doc/source/examples.txt Get the label widths at a specific depth of the index. This returns tuples of (label, width). ```python >>> ix = sf.IndexSecondGO(('1517-04-01', '1517-12-31', '1517-06-30')) >>> ix 1517-04-01T00:00:00 1517-12-31T00:00:00 1517-06-30T00:00:00 >>> tuple(ix.label_widths_at_depth(0)) ((np.datetime64('1517-04-01T00:00:00'), 1), (np.datetime64('1517-12-31T00:00:00'), 1), (np.datetime64('1517-06-30T00:00:00'), 1)) ``` -------------------------------- ### Create and Query IndexHierarchy Source: https://github.com/static-frame/static-frame/blob/master/doc/source/examples.txt Demonstrates creating an IndexHierarchy from product and selecting data using HLoc with various slicing and indexing techniques. ```python >>> ih = sf.IndexHierarchy.from_product(('a', 'b', 'c'), (1024, 4096, 2048), name='x') >>> ih a 1024 a 4096 a 2048 b 1024 b 4096 b 2048 c 1024 c 4096 c 2048 < >>> ih.loc[sf.HLoc[:, 4096]] a 4096 b 4096 c 4096 < >>> ih.loc[sf.HLoc[['a', 'c'], [1024, 2048]]] a 1024 a 2048 c 1024 c 2048 < ``` ```python >>> f = sf.Frame.from_fields(((10, 2, 8, 3), (False, True, True, False), ('1517-01-01', '1517-04-01', '1517-12-31', '1517-06-30')), index=sf.IndexHierarchy.from_product((0, 1), ('p', 'q')), columns=('a', 'b', 'c'), dtypes=dict(c=np.datetime64), name='x') >>> f a b c < 0 p 10 False 1517-01-01 0 q 2 True 1517-04-01 1 p 8 True 1517-12-31 1 q 3 False 1517-06-30 < >>> f.loc[sf.HLoc[:, 'q']] a b c < 0 q 2 True 1517-04-01 1 q 3 False 1517-06-30 < ``` -------------------------------- ### IndexYearGO values_at_depth() example Source: https://github.com/static-frame/static-frame/blob/master/doc/source/examples.txt Shows how to get all values at a specific depth within an IndexYearGO object using values_at_depth(). ```python >>> ix = sf.IndexYearGO(('1517', '1520', '1518')) >>> ix 1517 1520 1518 >>> ix.values_at_depth(0) ['1517' '1520' '1518'] ``` -------------------------------- ### IndexDateGO sample example Source: https://github.com/static-frame/static-frame/blob/master/doc/source/examples.txt Samples a specified number of elements from an IndexDateGO with a given seed for reproducibility. ```python >>> ix = sf.IndexDateGO(('1517-04-01', '1517-12', '1517-06-30')) >>> ix 1517-04-01 1517-12-01 1517-06-30 >>> ix.sample(2, seed=0) 1517-12-01 1517-06-30 ``` -------------------------------- ### IndexMicrosecondGO unique() example Source: https://github.com/static-frame/static-frame/blob/master/doc/source/examples.txt Demonstrates how to get unique values from an IndexMicrosecondGO object, including handling 'NaT' (Not a Time) values. ```python >>> ix = sf.IndexMicrosecondGO(('1620-09-16', 'NaT', '1620-11-21')) >>> ix 1620-09-16T00:00:00.000000 NaT 1620-11-21T00:00:00.000000 >>> ix.unique() ['1620-09-16T00:00:00.000000' 'NaT' '1620-11-21T00:00:00.000000'] ``` -------------------------------- ### IndexMillisecondGO rpartition() example Source: https://github.com/static-frame/static-frame/blob/master/doc/source/examples.txt Demonstrates the rpartition method on IndexMillisecondGO objects. This method splits each string at the last occurrence of the separator. ```python >>> ix = sf.IndexMillisecondGO(('1517-04-01', '1517-12-31', '1517-06-30')) >>> ix 1517-04-01T00:00:00.000 1517-12-31T00:00:00.000 1517-06-30T00:00:00.000 >>> ix.via_str.rpartition('X') [('', '', np.str_('1517-04-01T00:00:00.000')) ('', '', np.str_('1517-12-31T00:00:00.000')) ('', '', np.str_('1517-06-30T00:00:00.000'))] ``` -------------------------------- ### Get Values from Label-Mapped Reduction Source: https://github.com/static-frame/static-frame/blob/master/doc/source/examples.txt This example shows how to extract only the aggregated data arrays from a label-mapped reduction applied to a grouped FrameHE. ```python >>> f = sf.FrameHE.from_fields(((11, 4, 10, 2), (0, 8, 3, 8), (0, 1, 0, 1)), columns=('a', 'b', 'c'), name='x') >>> f a b c < 0 11 0 0 1 4 8 1 2 10 3 0 3 2 8 1 >>> tuple(f.iter_group_array('c').reduce.from_label_map({'b': np.min, 'a': np.max}).values()) ``` -------------------------------- ### IndexMicrosecond prod() example Source: https://github.com/static-frame/static-frame/blob/master/doc/source/examples.txt Shows the prod() method on IndexMicrosecond. This operation results in a UFuncTypeError. ```python >>> ix = sf.IndexMicrosecond(('1517-04-01', '1517-12-31', '1517-06-30')) >>> ix 1517-04-01T00:00:00.000000 1517-12-31T00:00:00.000000 1517-06-30T00:00:00.000000 >>> ix.prod() UFuncTypeError(, (dtype('>> bt = sf.Batch((('i', sf.Frame.from_fields(((10, 2, 8, 3), ('qrs ', 'XYZ', '123', ' wX '), ('1517-01-01', '1517-04-01', '1517-12-31', '1517-06-30')), columns=('a', 'b', 'c'), dtypes=dict(c=np.datetime64), name='x')), ('j', sf.Frame.from_fields(((10, 2, 8, 3), ('qrs ', 'XYZ', '123', ' wX ')), columns=('a', 'b'), index=('p', 'q', 'r', 's'), name='x')))) >>> bt >>> bt.via_str.startswith('X').to_frame() a b c < i 0 False False False i 1 False True False i 2 False False False i 3 False False False j p False False nan j q False True nan j r False False nan j s False False nan < ``` -------------------------------- ### IndexGO Interface Overview Source: https://github.com/static-frame/static-frame/blob/master/doc/source/examples.txt This snippet shows how to initialize an IndexGO object and provides an overview of its available interface methods and attributes. ```python >>> ix = sf.IndexGO((None, 'A', 1024, True), name='x') >>> ix None A 1024 True >>> ix.interface cls_name group doc < __init__(labels, /, *, loc_is_iloc,… IndexGO Constructor Initializer. Args: … from_difference(*others) IndexGO Constructor Construct a new Ind… from_intersection(*others) IndexGO Constructor Construct a new Ind… from_labels(labels, /, *, name) IndexGO Constructor Construct an Index … from_pandas(value, /) IndexGO Constructor Given a Pandas inde… from_union(*others) IndexGO Constructor Construct a new Ind… to_html(config, /, *, style_config) IndexGO Exporter Return an HTML tabl… to_html_datatables(fp, /, *, show, … IndexGO Exporter Return a complete H… to_pandas() IndexGO Exporter Return a Pandas Ind… to_series() IndexGO Exporter Return a Series wit… to_visidata() IndexGO Exporter Open an interactive… STATIC IndexGO Attribute Returns True when t… depth IndexGO Attribute int([x]) -> integer… dtype IndexGO Attribute Return the dtype of… index_types IndexGO Attribute Return a Series of … memory IndexGO Attribute A MemoryDisplay, pr… mloc IndexGO Attribute The memory location… … … … … via_re(pattern, flags, /).sub(repl,… IndexGO Accessor Regular Ex… Return the string o… via_re(pattern, flags, /).subn(repl… IndexGO Accessor Regular Ex… Perform the same op… via_hashlib(*, include_name, includ… IndexGO Accessor Hashlib Return the byte sig… via_hashlib(*, include_name, includ… IndexGO Accessor Hashlib via_hashlib(*, include_name, includ… IndexGO Accessor Hashlib via_hashlib(*, include_name, includ… IndexGO Accessor Hashlib via_hashlib(*, include_name, includ… IndexGO Accessor Hashlib via_hashlib(*, include_name, includ… IndexGO Accessor Hashlib via_hashlib(*, include_name, includ… IndexGO Accessor Hashlib via_hashlib(*, include_name, includ… IndexGO Accessor Hashlib via_hashlib(*, include_name, includ… IndexGO Accessor Hashlib via_hashlib(*, include_name, includ… IndexGO Accessor Hashlib via_type_clinic.to_hint() IndexGO Accessor Type Clinic Return the type hin… via_type_clinic.check(hint, /, *, f… IndexGO Accessor Type Clinic Given a hint (a typ… via_type_clinic.warn(hint, /, *, fa… IndexGO Accessor Type Clinic Given a hint (a typ… via_type_clinic.__call__(hint, /, *… IndexGO Accessor Type Clinic Given a hint (a typ… via_type_clinic.__repr__() IndexGO Accessor Type Clinic Return a compact st… < < < < ``` -------------------------------- ### Get Yarn dtype Source: https://github.com/static-frame/static-frame/blob/master/doc/source/examples.txt This example demonstrates how to retrieve the general dtype of a Yarn object. This represents the dtype of the 'values' column in the underlying representation. ```python >>> y = sf.Yarn.from_buses((sf.Bus.from_frames((sf.Frame(np.arange(6).reshape(3,2), index=('p', 'q', 'r'), columns=('a', 'b'), name='x'), sf.Frame((np.arange(6).reshape(3,2) % 2).astype(bool), index=('p', 'q', 'r'), columns=('c', 'd'), name='y')), name='i'), sf.Bus.from_frames((sf.Frame(np.arange(40, 46).reshape(3,2), index=('p', 'q', 'r'), columns=('a', 'b'), name='v'), sf.Frame((np.arange(6).reshape(3,2) % 3).astype(bool), index=('p', 'q', 'r'), columns=('c', 'd'), name='w')), name='j')), retain_labels=True) >>> y.dtype object ``` -------------------------------- ### IndexYearMonthGO - Sample Example Source: https://github.com/static-frame/static-frame/blob/master/doc/source/examples.txt Samples 2 elements from the IndexYearMonthGO with a fixed seed for reproducibility. ```python >>> ix = sf.IndexYearMonthGO(('1517-04', '1517-12', '1517-06')) >>> ix 1517-04 1517-12 1517-06 >>> ix.sample(2, seed=0) 1517-12 1517-06 ``` -------------------------------- ### Get the tail of the index Source: https://github.com/static-frame/static-frame/blob/master/doc/source/examples.txt Use `tail()` to retrieve the last elements of the index. This example shows an attempt to use a string that causes a TypeError. ```python >>> ix = sf.IndexYear(('1517', '1520', '1518')) >>> ix.tail("1517-12") TypeError("bad operand type for unary -: 'str'") ``` -------------------------------- ### IndexDate.sample() Example Source: https://github.com/static-frame/static-frame/blob/master/doc/source/examples.txt Shows how to randomly sample elements from an IndexDate with a specified seed for reproducibility. ```python >>> ix = sf.IndexDate(('1517-04-01', '1517-12', '1517-06-30')) >>> ix 1517-04-01 1517-12-01 1517-06-30 >>> ix.sample(2, seed=0) 1517-12-01 1517-06-30 ``` -------------------------------- ### IndexSecondGO sort() Example Source: https://github.com/static-frame/static-frame/blob/master/doc/source/examples.txt Demonstrates sorting an IndexSecondGO in ascending and descending order. The default is ascending. ```python >>> ix = sf.IndexSecondGO(('1517-04-01', '1517-12-31', '1517-06-30')) >>> ix 1517-04-01T00:00:00 1517-12-31T00:00:00 1517-06-30T00:00:00 >>> ix.sort() 1517-04-01T00:00:00 1517-06-30T00:00:00 1517-12-31T00:00:00 >>> ix.sort(ascending=False) 1517-12-31T00:00:00 1517-06-30T00:00:00 1517-04-01T00:00:00 ``` -------------------------------- ### Get Yarn index Source: https://github.com/static-frame/static-frame/blob/master/doc/source/examples.txt This example demonstrates how to access the index of a Yarn object. The index is an IndexHierarchy that represents the labels for the Buses and Frames within the Yarn. ```python >>> y = sf.Yarn.from_buses((sf.Bus.from_frames((sf.Frame(np.arange(6).reshape(3,2), index=('p', 'q', 'r'), columns=('a', 'b'), name='x'), sf.Frame((np.arange(6).reshape(3,2) % 2).astype(bool), index=('p', 'q', 'r'), columns=('c', 'd'), name='y')), name='i'), sf.Bus.from_buses((sf.Frame(np.arange(40, 46).reshape(3,2), index=('p', 'q', 'r'), columns=('a', 'b'), name='v'), sf.Frame((np.arange(6).reshape(3,2) % 3).astype(bool), index=('p', 'q', 'r'), columns=('c', 'd'), name='w')), name='j')), retain_labels=True) >>> y.index i x i y j v j w < < ``` -------------------------------- ### Get label widths at depth for IndexMillisecondGO Source: https://github.com/static-frame/static-frame/blob/master/doc/source/examples.txt The `label_widths_at_depth` method returns the width of each label at a specified depth. This example shows widths at depth 0. ```python >>> ix = sf.IndexMillisecondGO(('1517-04-01', '1517-12-31', '1517-06-30')) >>> tuple(ix.label_widths_at_depth(0)) ((np.datetime64('1517-04-01T00:00:00.000'), 1), (np.datetime64('1517-12-31T00:00:00.000'), 1), (np.datetime64('1517-06-30T00:00:00.000'), 1)) ``` -------------------------------- ### Get Label Widths at Depth for IndexMillisecond Source: https://github.com/static-frame/static-frame/blob/master/doc/source/examples.txt The `label_widths_at_depth()` method returns the width of labels at a specified depth. This example shows widths for depth 0. ```python >>> ix = sf.IndexMillisecond(('1517-04-01', '1517-12-31', '1517-06-30')) >>> ix 1517-04-01T00:00:00.000 1517-12-31T00:00:00.000 1517-06-30T00:00:00.000 >>> tuple(ix.label_widths_at_depth(0)) ((np.datetime64('1517-04-01T00:00:00.000'), 1), (np.datetime64('1517-12-31T00:00:00.000'), 1), (np.datetime64('1517-06-30T00:00:00.000'), 1)) ``` -------------------------------- ### IndexYearMonthGO from_labels() example Source: https://github.com/static-frame/static-frame/blob/master/doc/source/examples.txt Demonstrates creating an IndexYearMonthGO directly from a list of year-month labels. ```python >>> sf.IndexYearMonthGO.from_labels(('1517-04', '1517-12', '1517-06')) 1517-04 1517-12 1517-06 ``` -------------------------------- ### IndexMillisecondGO title() example Source: https://github.com/static-frame/static-frame/blob/master/doc/source/examples.txt Demonstrates the title method on IndexMillisecondGO objects. This method converts each string to title case, where words start with an uppercase character. ```python >>> ix = sf.IndexMillisecondGO(('1517-04-01', '1517-12-31', '1517-06-30')) >>> ix 1517-04-01T00:00:00.000 1517-12-31T00:00:00.000 1517-06-30T00:00:00.000 >>> ix.via_str.title() ['1517-04-01T00:00:00.000' '1517-12-31T00:00:00.000' '1517-06-30T00:00:00.000'] ``` -------------------------------- ### IndexMinute Initialization Source: https://github.com/static-frame/static-frame/blob/master/doc/source/examples.txt Demonstrates the initialization of an IndexMinute object with a list of date strings. The output shows the formatted dates with time components. ```python >>> sf.IndexMinute(('1517-04-01', '1517-12', '1517-06-30')) 1517-04-01T00:00 1517-12-01T00:00 1517-06-30T00:00 ``` -------------------------------- ### Series via_re().match() Example Source: https://github.com/static-frame/static-frame/blob/master/doc/source/examples.txt Applies a regular expression match to a Series. This method returns a boolean Series indicating matches from the start of the string. ```python >>> s = sf.Series((10, 2, 8), index=('a', 'b', 'c')) >>> s a 10 b 2 c 8 < >>> s.via_re('[X123]').match() a True b True c False < ``` -------------------------------- ### Basic C-Extension Setup with NumPy Headers Source: https://github.com/static-frame/static-frame/blob/master/doc/source/articles/np_ext.txt This snippet shows the essential C code required to set up a NumPy C-extension, including including NumPy headers and calling `import_array()` to initialize the NumPy C API. ```c #include #include // ... other C code ... static PyMethodDef MyModule_methods[] = { // ... method definitions ... {NULL, NULL, 0, NULL} /* Sentinel */ }; static struct PyModuleDef MyModule = { PyModuleDef_HEAD_INIT, "my_module", /* name of module */ NULL, /* module documentation, may be NULL */ -1, /* size of per-interpreter state of the module, or -1 if the module keeps state in global variables. */ MyModule_methods }; PyMODINIT_FUNC PyInit_my_module(void) { import_array(); // Initialize NumPy C API return PyModule_Create(&MyModule); } ``` -------------------------------- ### Get Yarn dtypes Source: https://github.com/static-frame/static-frame/blob/master/doc/source/examples.txt This example shows how to retrieve the dtypes for each column within a Yarn object. This provides a detailed view of the data types across all Frames. ```python >>> y = sf.Yarn.from_buses((sf.Bus.from_frames((sf.Frame(np.arange(6).reshape(3,2), index=('p', 'q', 'r'), columns=('a', 'b'), name='x'), sf.Frame((np.arange(6).reshape(3,2) % 2).astype(bool), index=('p', 'q', 'r'), columns=('c', 'd'), name='y')), name='i'), sf.Bus.from_frames((sf.Frame(np.arange(40, 46).reshape(3,2), index=('p', 'q', 'r'), columns=('a', 'b'), name='v'), sf.Frame((np.arange(6).reshape(3,2) % 3).astype(bool), index=('p', 'q', 'r'), columns=('c', 'd'), name='w')), name='j')), retain_labels=True) >>> y.dtypes a b c d < i x int64 int64 None None i y None None bool bool j v int64 int64 None None j w None None bool bool < < ``` -------------------------------- ### Display Index with default configuration Source: https://github.com/static-frame/static-frame/blob/master/doc/source/examples.txt Shows how to display an Index object using the `display()` method with default configuration. ```python >>> ix = sf.Index((None, 'A', 1024, True), name='x') >>> ix.display() None A 1024 True ``` -------------------------------- ### Get time tuple from IndexNanosecond (Error Example) Source: https://github.com/static-frame/static-frame/blob/master/doc/source/examples.txt Attempting to use `.via_dt.timetuple()` on an IndexNanosecond with a `datetime64[ns]` dtype results in a `RuntimeError` because this operation is not supported for this dtype. ```python >>> ix = sf.IndexNanosecond(('1789-05-05', '1789-12-31', '1799-11-09')) >>> ix 1789-05-05T00:00:00.000000000 1789-12-31T00:00:00.000000000 1799-11-09T00:00:00.000000000 >>> ix.via_dt.timetuple() RuntimeError('invalid dtype (datetime64[ns]) for date operation') ``` -------------------------------- ### Get Minimum Value with IndexHourGO Source: https://github.com/static-frame/static-frame/blob/master/doc/source/examples.txt Demonstrates the `min` method for retrieving the earliest datetime value from an `IndexHourGO` object. This is useful for finding the start of a time range. ```python >>> ix = sf.IndexHourGO(('1517-04-01', '1517-12-31', '1517-06-30')) >>> ix 1517-04-01T00 1517-12-31T00 1517-06-30T00 >>> ix.min() 1517-04-01T00 ``` -------------------------------- ### Get ISO format from IndexNanosecond (Error Example) Source: https://github.com/static-frame/static-frame/blob/master/doc/source/examples.txt Calling `.via_dt.isoformat()` on an IndexNanosecond with `datetime64[ns]` dtype raises a `RuntimeError` as this date operation is not supported for the given dtype. ```python >>> ix = sf.IndexNanosecond(('1789-05-05', '1789-12-31', '1799-11-09')) >>> ix 1789-05-05T00:00:00.000000000 1789-12-31T00:00:00.000000000 1799-11-09T00:00:00.000000000 >>> ix.via_dt.isoformat() RuntimeError('invalid dtype (datetime64[ns]) for date operation') ``` -------------------------------- ### IndexYearMonthGO from_union() example Source: https://github.com/static-frame/static-frame/blob/master/doc/source/examples.txt Illustrates creating an IndexYearMonthGO by finding the union of two existing IndexYearMonthGO objects. ```python >>> ix1 = sf.IndexYearMonthGO.from_labels(('1517-04', '1517-12', '1517-06')) >>> ix1 1517-04 1517-12 1517-06 >>> ix2 = sf.IndexYearMonthGO.from_labels(('2022-04', '2021-12', '2018-06')) >>> ix2 2022-04 2021-12 2018-06 >>> sf.IndexYearMonthGO.from_union(ix1, ix2) 1517-04 1517-06 1517-12 2018-06 2021-12 2022-04 ``` -------------------------------- ### IndexMicrosecond Initialization from Difference Source: https://github.com/static-frame/static-frame/blob/master/doc/source/examples.txt Shows how to create an IndexMicrosecond by calculating the difference between two other IndexMicrosecond instances. The resulting index appears identical to the first operand in this example. ```python >>> ix1 = sf.IndexMicrosecond.from_labels(('1517-04-01', '1517-12-31', '1517-06-30')) >>> ix1 1517-04-01T00:00:00.000000 1517-12-31T00:00:00.000000 1517-06-30T00:00:00.000000 >>> ix2 = sf.IndexMicrosecond.from_labels(('2022-04-01', '2021-12-31', '2018-06-30')) >>> ix2 2022-04-01T00:00:00.000000 2021-12-31T00:00:00.000000 2018-06-30T00:00:00.000000 >>> sf.IndexMicrosecond.from_difference(ix1, ix2) 1517-04-01T00:00:00.000000 1517-12-31T00:00:00.000000 1517-06-30T00:00:00.000000 ``` -------------------------------- ### Get character by index from strings Source: https://github.com/static-frame/static-frame/blob/master/doc/source/examples.txt The `via_str.__getitem__()` method allows accessing individual characters from strings within an IndexGO by their index. This example shows accessing the last character. ```python >>> ix = sf.IndexGO(('qrs ', 'XYZ', '123', ' wX ')) >>> ix qrs XYZ 123 wX < >>> ix.via_str[-1] [' ' 'Z' '3' ' '] ``` -------------------------------- ### IndexSecondGO tail() Example Source: https://github.com/static-frame/static-frame/blob/master/doc/source/examples.txt Demonstrates using the tail() method. Note that providing a string like '1517-12' results in a TypeError. ```python >>> ix = sf.IndexSecondGO(('1517-04-01', '1517-12-31', '1517-06-30')) >>> ix 1517-04-01T00:00:00 1517-12-31T00:00:00 1517-06-30T00:00:00 >>> ix.tail("1517-12") TypeError("bad operand type for unary -: 'str'") ```