<s> import numpy as np <EOL> from pandas import * <EOL> import pandas . core . sparse as spm <EOL> import pandas . compat as compat <EOL> reload ( spm ) <EOL> from pandas . core . sparse import * <EOL> N = <NUM_LIT> <EOL> arr1 = np . arange ( N ) <EOL> index = Index ( np . arange ( N ) ) <EOL> off = N // <NUM_LIT:10> <EOL> arr1 [ off : <NUM_LIT:2> * off ] = np . NaN <EOL> arr1 [ <NUM_LIT:4> * off : <NUM_LIT:5> * off ] = np . NaN <EOL> arr1 [ <NUM_LIT:8> * off : <NUM_LIT:9> * off ] = np . NaN <EOL> arr2 = np . arange ( N ) <EOL> arr2 [ <NUM_LIT:3> * off // <NUM_LIT:2> : <NUM_LIT:2> * off + off // <NUM_LIT:2> ] = np . NaN <EOL> arr2 [ <NUM_LIT:8> * off + off // <NUM_LIT:2> : <NUM_LIT:9> * off + off // <NUM_LIT:2> ] = np . NaN <EOL> s1 = SparseSeries ( arr1 , index = index ) <EOL> s2 = SparseSeries ( arr2 , index = index ) <EOL> is1 = SparseSeries ( arr1 , kind = '<STR_LIT>' , index = index ) <EOL> is2 = SparseSeries ( arr2 , kind = '<STR_LIT>' , index = index ) <EOL> s1_dense = s1 . to_dense ( ) <EOL> s2_dense = s2 . to_dense ( ) <EOL> if compat . is_platform_linux ( ) : <EOL> pth = '<STR_LIT>' <EOL> else : <EOL> pth = '<STR_LIT>' <EOL> dm = DataFrame . load ( pth ) <EOL> sdf = dm . to_sparse ( ) <EOL> def new_data_like ( sdf ) : <EOL> new_data = { } <EOL> for col , series in compat . iteritems ( sdf ) : <EOL> new_data [ col ] = SparseSeries ( np . random . randn ( len ( series . sp_values ) ) , <EOL> index = sdf . index , <EOL> sparse_index = series . sp_index , <EOL> fill_value = series . fill_value ) <EOL> return SparseDataFrame ( new_data ) <EOL> dwp = Panel . fromDict ( { '<STR_LIT:foo>' : dm } ) <EOL> lp = stack_sparse_frame ( sdf ) <EOL> swp = SparsePanel ( { '<STR_LIT:A>' : sdf } ) <EOL> swp = SparsePanel ( { '<STR_LIT:A>' : sdf , <EOL> '<STR_LIT:B>' : sdf , <EOL> '<STR_LIT:C>' : sdf , <EOL> '<STR_LIT:D>' : sdf } ) <EOL> y = sdf <EOL> x = SparsePanel ( { '<STR_LIT>' : sdf + new_data_like ( sdf ) / <NUM_LIT:10> , <EOL> '<STR_LIT>' : sdf + new_data_like ( sdf ) / <NUM_LIT:10> } ) <EOL> dense_y = sdf <EOL> dense_x = x . to_dense ( ) <EOL> dense_model = ols ( y = dense_y , x = dense_x ) <EOL> import pandas . stats . plm as plm <EOL> import pandas . stats . interface as face <EOL> reload ( plm ) <EOL> reload ( face ) </s>
