in [ ]sampler np random randint( len(bag)size= in [ ]sampler out[ ]array([ ]in [ ]draws bag take(samplerin [ ]draws out[ ]array( - - - ]computing indicator/dummy variables another type of transformation for statistical modeling or machine learning applications is converting categorical variable into "dummyor "indicatormatrix if column in dataframe has distinct valuesyou would derive matrix or dataframe containing columns containing all ' and ' pandas has get_dummies function for doing thisthough devising one yourself is not difficult let' return to an earlier example dataframein [ ]df dataframe({'key'[' '' '' '' '' '' ']'data 'range( )}in [ ]pd get_dummies(df['key']out[ ] in some casesyou may want to add prefix to the columns in the indicator dataframewhich can then be merged with the other data get_dummies has prefix argument for doing just thisin [ ]dummies pd get_dummies(df['key']prefix='key'in [ ]df_with_dummy df[['data ']join(dummiesin [ ]df_with_dummy out[ ]data key_a key_b key_c data transformation www it-ebooks info