Sindbad~EG File Manager
�
Mٜg�� � �F � d Z ddlmZ ddlZddlmZ ddlmZmZmZm Z m
Z
ddlZddlm
Z
ddlmZ ddlZddlZddlZddlmZ dd lmZmZmZmZmZmZ ddlZddlZdd
lmZ ddl m!Z!m"Z"m#Z# ddl$m%Z% dd
l&m'Z(m)Z)m*Z* ddl+m,Z, ddl-m.Z. ddl/m0Z0 ddl1m2Z2 ddl3m4Z4 ddl5m6Z7 ddl8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z> ddl?m@Z@mAZAmBZBmCZC ddlDmEZEmFZF ddlGmHZHmIZImJZJ ddlKmLZLmMZMmNZNmOZOmPZPmQZQmRZRmSZSmTZT ddlUmVZVmWZWmXZXmYZYmZZZm[Z[m\Z\m]Z]m^Z^m_Z_m`Z`maZambZbmcZcmdZdmeZemfZf ddlgmhZh ddlimjZjmkZkmlZl ddlmmnZnmoZo ddlpmqZqmrZsmtZtmuZumvZv ddlwmxZx ddlymzZz dd l{m|Z| dd!l}m~Z~ dd"lm�Z�m�Z�m�Z�m�Z�m�Z� dd#l�m�Z� dd$l�m�Z�m�Z�m�Z� dd%l�m�Z�m�Z� dd&l�m�Z� dd'l�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z� dd(l�m�Z�m�Z� dd)l�m�Z�m�Z� dd*l�m�Z�m�Z� dd+l�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z� dd,l�m�Z� dd-l�m�Z� dd.l�m�Z� dd/l�m�Z� dd0l�m�Z�m�Z�m�Z� dd1l�m�Z� dd2l�m�Z�m�Z� dd3l�m�Z�m�Z�m�Z� ddl�Z�er�ddl�Z�dd4l�m�Z� dd5l�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z�m�Z� dd6l�m�Z� dd7l�m�Z� dd8l�m�Z� dd9l�m�Z� d:d;d<d=d>d?d@dA�Z�dB�Z G dC� d;e�e~� Z�dFdD��Z dGdE��Zy)Ha#
DataFrame
---------
An efficient 2D container for potentially mixed-type time series or other
labeled data series.
Similar to its R counterpart, data.frame, except providing automatic data
alignment and a host of useful data manipulation methods having to do with the
labeling information
� )�annotationsN)�abc)�Hashable�Iterable�Iterator�Mapping�Sequence)� signature)�StringIO)�dedent)�
TYPE_CHECKING�Any�Callable�Literal�cast�overload)�ma)�
get_option�using_copy_on_write�warn_copy_on_write)�_get_option)�algos�lib�
properties)�
duplicated)�is_range_indexer)�PYPY)� REF_COUNT)�import_optional_dependency)�function)�ChainedAssignmentError�InvalidIndexError�_chained_assignment_method_msg�_chained_assignment_msg�&_chained_assignment_warning_method_msg�_chained_assignment_warning_msg)�Appender�Substitution�deprecate_nonkeyword_arguments�doc)�find_stack_level�rewrite_warning)�validate_ascending�validate_bool_kwarg�validate_percentile) �LossySetitemError�can_hold_element�"construct_1d_arraylike_from_scalar�"construct_2d_arraylike_from_scalar�find_common_type�infer_dtype_from_scalar�invalidate_string_dtypes�maybe_box_native�maybe_downcast_to_dtype)�infer_dtype_from_object�is_1d_only_ea_dtype�
is_array_like�
is_bool_dtype�is_dataclass�is_dict_like�is_float�is_float_dtype�is_hashable�
is_integer�is_integer_dtype�is_iterator�is_list_like� is_scalar�is_sequence�needs_i8_conversion�pandas_dtype)�
concat_compat)�
ArrowDtype�BaseMaskedDtype�ExtensionDtype)�isna�notna)�
algorithms�common�nanops�ops� roperator)�CachedAccessor)�reconstruct_and_relabel_result)�
take_2d_multi)�OpsMixin)�BaseMaskedArray�
DatetimeArray�ExtensionArray�PeriodArray�TimedeltaArray)�SparseFrameAccessor)�ensure_wrapped_if_datetimelike�sanitize_array�sanitize_masked_array)�NDFrame�make_doc)�check_key_length)�
DatetimeIndex�Index�PeriodIndex�
default_index�ensure_index�ensure_index_from_sequences)�
MultiIndex�maybe_droplevels)�check_bool_indexer�check_dict_or_set_indexers)�ArrayManager�BlockManager)
�
arrays_to_mgr�dataclasses_to_dicts�dict_to_mgr�
mgr_to_mgr�ndarray_to_mgr�nested_data_to_arrays�rec_array_to_mgr�reorder_arrays� to_arrays�treat_as_nested)�selectn)�melt)�Series)�_shared_docs)�get_group_index�lexsort_indexer�nargsort)�
get_handle)�console�format)�INFO_DOCSTRING�
DataFrameInfo�frame_sub_kwargs)�BlockValuesRefs)0�AggFuncType�AnyAll�AnyArrayLike� ArrayLike�Axes�Axis�AxisInt�ColspaceArgType�CompressionOptions�CorrelationMethod�DropKeep�Dtype�DtypeObj�FilePath�FloatFormatType�FormattersType� Frequency�FromDictOrient�IgnoreRaise�IndexKeyFunc�
IndexLabel�JoinValidate�Level�MergeHow�
MergeValidate�MutableMappingT�NaAction�
NaPosition�NsmallestNlargestKeep�PythonFuncType�QuantileInterpolation�
ReadBuffer�
ReindexMethod�Renamer�Scalar�Self�SequenceNotStr�SortKind�StorageOptions�Suffixes�ToGbqIfexist�ToStataByteorder�ToTimestampHow�
UpdateJoin�ValueKeyFunc�WriteBuffer�
XMLParsers�npt��DataFrameGroupBy�� DataFrame)�SingleDataManager��Stylerzindex, columnsr� z{0 or 'index', 1 or 'columns'}z�axis : {0 or 'index', 1 or 'columns'}, default 0
If 0 or 'index': apply function to each column.
If 1 or 'columns': apply function to each row.zj
inplace : bool, default False
Whether to modify the DataFrame rather than creating a new one.a
by : str or list of str
Name or list of names to sort by.
- if `axis` is 0 or `'index'` then `by` may contain index
levels and/or column labels.
- if `axis` is 1 or `'columns'` then `by` may contain column
levels and/or index labels.a�
labels : array-like, optional
New labels / index to conform the axis specified by 'axis' to.
index : array-like, optional
New labels for the index. Preferably an Index object to avoid
duplicating data.
columns : array-like, optional
New labels for the columns. Preferably an Index object to avoid
duplicating data.
axis : int or str, optional
Axis to target. Can be either the axis name ('index', 'columns')
or number (0, 1).)�axes�klass�axes_single_arg�axis�inplace�optional_by�optional_reindexa�
Merge DataFrame or named Series objects with a database-style join.
A named Series object is treated as a DataFrame with a single named column.
The join is done on columns or indexes. If joining columns on
columns, the DataFrame indexes *will be ignored*. Otherwise if joining indexes
on indexes or indexes on a column or columns, the index will be passed on.
When performing a cross merge, no column specifications to merge on are
allowed.
.. warning::
If both key columns contain rows where the key is a null value, those
rows will be matched against each other. This is different from usual SQL
join behaviour and can lead to unexpected results.
Parameters
----------%s
right : DataFrame or named Series
Object to merge with.
how : {'left', 'right', 'outer', 'inner', 'cross'}, default 'inner'
Type of merge to be performed.
* left: use only keys from left frame, similar to a SQL left outer join;
preserve key order.
* right: use only keys from right frame, similar to a SQL right outer join;
preserve key order.
* outer: use union of keys from both frames, similar to a SQL full outer
join; sort keys lexicographically.
* inner: use intersection of keys from both frames, similar to a SQL inner
join; preserve the order of the left keys.
* cross: creates the cartesian product from both frames, preserves the order
of the left keys.
on : label or list
Column or index level names to join on. These must be found in both
DataFrames. If `on` is None and not merging on indexes then this defaults
to the intersection of the columns in both DataFrames.
left_on : label or list, or array-like
Column or index level names to join on in the left DataFrame. Can also
be an array or list of arrays of the length of the left DataFrame.
These arrays are treated as if they are columns.
right_on : label or list, or array-like
Column or index level names to join on in the right DataFrame. Can also
be an array or list of arrays of the length of the right DataFrame.
These arrays are treated as if they are columns.
left_index : bool, default False
Use the index from the left DataFrame as the join key(s). If it is a
MultiIndex, the number of keys in the other DataFrame (either the index
or a number of columns) must match the number of levels.
right_index : bool, default False
Use the index from the right DataFrame as the join key. Same caveats as
left_index.
sort : bool, default False
Sort the join keys lexicographically in the result DataFrame. If False,
the order of the join keys depends on the join type (how keyword).
suffixes : list-like, default is ("_x", "_y")
A length-2 sequence where each element is optionally a string
indicating the suffix to add to overlapping column names in
`left` and `right` respectively. Pass a value of `None` instead
of a string to indicate that the column name from `left` or
`right` should be left as-is, with no suffix. At least one of the
values must not be None.
copy : bool, default True
If False, avoid copy if possible.
.. note::
The `copy` keyword will change behavior in pandas 3.0.
`Copy-on-Write
<https://pandas.pydata.org/docs/dev/user_guide/copy_on_write.html>`__
will be enabled by default, which means that all methods with a
`copy` keyword will use a lazy copy mechanism to defer the copy and
ignore the `copy` keyword. The `copy` keyword will be removed in a
future version of pandas.
You can already get the future behavior and improvements through
enabling copy on write ``pd.options.mode.copy_on_write = True``
indicator : bool or str, default False
If True, adds a column to the output DataFrame called "_merge" with
information on the source of each row. The column can be given a different
name by providing a string argument. The column will have a Categorical
type with the value of "left_only" for observations whose merge key only
appears in the left DataFrame, "right_only" for observations
whose merge key only appears in the right DataFrame, and "both"
if the observation's merge key is found in both DataFrames.
validate : str, optional
If specified, checks if merge is of specified type.
* "one_to_one" or "1:1": check if merge keys are unique in both
left and right datasets.
* "one_to_many" or "1:m": check if merge keys are unique in left
dataset.
* "many_to_one" or "m:1": check if merge keys are unique in right
dataset.
* "many_to_many" or "m:m": allowed, but does not result in checks.
Returns
-------
DataFrame
A DataFrame of the two merged objects.
See Also
--------
merge_ordered : Merge with optional filling/interpolation.
merge_asof : Merge on nearest keys.
DataFrame.join : Similar method using indices.
Examples
--------
>>> df1 = pd.DataFrame({'lkey': ['foo', 'bar', 'baz', 'foo'],
... 'value': [1, 2, 3, 5]})
>>> df2 = pd.DataFrame({'rkey': ['foo', 'bar', 'baz', 'foo'],
... 'value': [5, 6, 7, 8]})
>>> df1
lkey value
0 foo 1
1 bar 2
2 baz 3
3 foo 5
>>> df2
rkey value
0 foo 5
1 bar 6
2 baz 7
3 foo 8
Merge df1 and df2 on the lkey and rkey columns. The value columns have
the default suffixes, _x and _y, appended.
>>> df1.merge(df2, left_on='lkey', right_on='rkey')
lkey value_x rkey value_y
0 foo 1 foo 5
1 foo 1 foo 8
2 bar 2 bar 6
3 baz 3 baz 7
4 foo 5 foo 5
5 foo 5 foo 8
Merge DataFrames df1 and df2 with specified left and right suffixes
appended to any overlapping columns.
>>> df1.merge(df2, left_on='lkey', right_on='rkey',
... suffixes=('_left', '_right'))
lkey value_left rkey value_right
0 foo 1 foo 5
1 foo 1 foo 8
2 bar 2 bar 6
3 baz 3 baz 7
4 foo 5 foo 5
5 foo 5 foo 8
Merge DataFrames df1 and df2, but raise an exception if the DataFrames have
any overlapping columns.
>>> df1.merge(df2, left_on='lkey', right_on='rkey', suffixes=(False, False))
Traceback (most recent call last):
...
ValueError: columns overlap but no suffix specified:
Index(['value'], dtype='object')
>>> df1 = pd.DataFrame({'a': ['foo', 'bar'], 'b': [1, 2]})
>>> df2 = pd.DataFrame({'a': ['foo', 'baz'], 'c': [3, 4]})
>>> df1
a b
0 foo 1
1 bar 2
>>> df2
a c
0 foo 3
1 baz 4
>>> df1.merge(df2, how='inner', on='a')
a b c
0 foo 1 3
>>> df1.merge(df2, how='left', on='a')
a b c
0 foo 1 3.0
1 bar 2 NaN
>>> df1 = pd.DataFrame({'left': ['foo', 'bar']})
>>> df2 = pd.DataFrame({'right': [7, 8]})
>>> df1
left
0 foo
1 bar
>>> df2
right
0 7
1 8
>>> df1.merge(df2, how='cross')
left right
0 foo 7
1 foo 8
2 bar 7
3 bar 8
c �X2 � � e Zd ZU dZddhej
z ZdZeee e
j fZdhZ
ded<