Skip to content

Commit 5c62063

Browse files
committed
Addition of asv for pivot_table of categorical data with observed keyword.
1 parent 416e9c8 commit 5c62063

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

asv_bench/benchmarks/reshape.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ def setup(self):
128128
'value2': np.random.randn(N),
129129
'value3': np.random.randn(N)})
130130

131+
self.df2 = pd.DataFrame({'col1': list('abcde'), 'col2': list('fghij'), 'col3': [1, 2, 3, 4, 5]})
132+
self.df2.col1 = self.df2.col1.astype('category')
133+
self.df2.col2 = self.df2.col2.astype('category')
134+
131135
def time_pivot_table(self):
132136
self.df.pivot_table(index='key1', columns=['key2', 'key3'])
133137

@@ -139,6 +143,10 @@ def time_pivot_table_margins(self):
139143
self.df.pivot_table(index='key1', columns=['key2', 'key3'],
140144
margins=True)
141145

146+
def time_pivot_table_categorical(self):
147+
self.df2.pivot_table(index='col1', values='col3', columns='col2',
148+
aggfunc=np.sum, fill_value=0, observed=True)
149+
142150

143151
class Crosstab(object):
144152

0 commit comments

Comments
 (0)