How To Get Frequency Count Of Column Values For Each Unique Pair Of Columns In Pandas?
I have a Dataframe that looks like below data = [(datetime.datetime(2021, 2, 10, 7, 49, 7, 118658), u'12.100.90.10', u'100.100.12.1', u'LT_DOWN'), (datetime.datetime(2021, 2
Solution 1:
You can use the same solution you are referring to and sum, and unstack along last axis:
pd.crosstab(
index=df['date'].dt.floor('1min'),
columns=[
df['start'],
df['end'],
df['type'].str.extract(r'(\w+)_', expand=False)
],
).astype(bool).sum().unstack(-1, fill_value=0)
type LT MA PL
start end
10.10.80.10 10.55.10.1 0 1 1
10.100.80.10 10.55.10.1 0 0 1
12.100.90.10 100.100.12.1 1 0 1
Post a Comment for "How To Get Frequency Count Of Column Values For Each Unique Pair Of Columns In Pandas?"