python - Reduce Two Pandas Series to a Single One -


problem:

i'd take series 1 , series 2 , create new series values (series 1, series 2). essentially, have 2 pandas series combine one. although values represented ints factors.

ex.

series 1   series 2        series 3   1            2      ---   (1,2)   2            3         (2,3)   3            4      ---   (3,4) 

what i've tried

pandas: combine 2 columns in dataframe

the pandas functions:

concat, merge, join

so far i've been able combine values, (ie. add elements together, append series each other, or merge based on values). because dataset large, i'm looking avoid loops. although thats way can think far. feel should pretty easy accomplish power of pandas.

any ideas? taking look!

what going this?

in [1]: s1 = series([1,2,3])  in [2]: s2 = series([2,3,4])  in [4]: series(zip(s1,s2)) out[4]:  0    (1, 2) 1    (2, 3) 2    (3, 4) dtype: object 

here's idea, not sure if suited want...maybe

in [70]: s = series([1,2,4,5,6]) 

a discrete quantizer (basically bins things, can supply bins if want) produces categorical

in [71]: pd.qcut(s,2) out[71]:  categorical:  array(['[1, 4]', '[1, 4]', '[1, 4]', '(4, 6]', '(4, 6]'], dtype=object) levels (2): index(['[1, 4]', '(4, 6]'], dtype=object) 

which can value_counts on

in [72]: pd.value_counts(pd.qcut(s,2)) out[72]:  [1, 4]    3 (4, 6]    2 dtype: int64 

Comments