iode.Lists.from_series
- Lists.from_series(s: Series)[source]
Copy the pandas Series s into the IODE Lists database. The IODE list names to copy are deduced from the index of the Series.
- Parameters:
- s: Series
pandas Series containing the IODE lists to copy into the IODE Lists database.
See also
Notes
The index of the passed Series is sorted in alphabetical order before copying to IODE Lists database.
Examples
>>> from iode import lists >>> import pandas as pd >>> lists.clear() >>> len(lists) 0
>>> # create the pandas Series >>> names = ["SEMICOLON_LST", "COMMA_LST", "WHITESPACE_LST", "TAB_LST", "MIX_LST"] >>> semicolon_lst = "A;B;C;D;E;F" >>> comma_lst = "A,B,C,D,E,F" >>> whitespace_lst = "A B C D E F" >>> tab_lst = "A B C D E F" >>> mix_lst = " A;B,C D E;F " >>> data = [semicolon_lst, comma_lst, whitespace_lst, tab_lst, mix_lst] >>> s = pd.Series(data=data, index=names, dtype=str, name="Lists") >>> # display the pandas series >>> s SEMICOLON_LST A;B;C;D;E;F COMMA_LST A,B,C,D,E,F WHITESPACE_LST A B C D E F TAB_LST A B C D E F MIX_LST A;B,C D E;F Name: Lists, dtype: object
>>> # load into the IODE Lists database >>> lists.from_series(s) >>> len(lists) 5
>>> lists.names ['COMMA_LST', 'MIX_LST', 'SEMICOLON_LST', 'TAB_LST', 'WHITESPACE_LST'] >>> lists["SEMICOLON_LST"] ['A', 'B', 'C', 'D', 'E', 'F'] >>> # note: when added or updated, an IODE list is normalized. >>> # - leading and trailing whitespaces are stripped >>> # - items of the IODE list are separated by a semicolon >>> lists["COMMA_LST"] ['A', 'B', 'C', 'D', 'E', 'F'] >>> lists["MIX_LST"] ['A', 'B', 'C', 'D', 'E', 'F']