Пример #1
0
def split(series):
    '''
    Split values
    
    The index is dropped, but this may change in the future.
    
    Parameters
    ----------
    series : pd.Series
        Series with numpy array-like values.
        
    Returns
    -------
    pd.Series
        Series with values split across rows.
        
    Examples
    --------
    >>> series = pd.Series([[1,2],[1,2],[3,4,5]])
    >>> series
    0       [1, 2]
    1       [1, 2]
    2    [3, 4, 5]
    dtype: object
    >>> split(series)
    0    1
    1    2
    2    1
    3    2
    4    3
    5    4
    6    5
    dtype: object
    '''
    s = df_.split_array_like(series.apply(list).to_frame('column'), 'column')['column']
    s.name = series.name
    return s
 def test_split_a(self, df, df_split_a):
     '''When split on 'a', correct split'''
     assert split_array_like(df, 'a').equals(df_split_a)
     assert split_array_like(df, ('a',)).equals(df_split_a)
 def test_split_a_b(self, df, df_split_a_b):
     '''When split on 'a' and 'b', correct split'''
     assert split_array_like(df, ('a', 'b')).equals(df_split_a_b) # Note: test should allow index to differ
     assert split_array_like(df, iter(('a', 'b'))).equals(df_split_a_b)
     assert split_array_like(df.drop('check', axis=1)).equals(df_split_a_b.drop('check', axis=1))