File tree 3 files changed +47
-0
lines changed
solution/0100-0199/0180.Consecutive Numbers
3 files changed +47
-0
lines changed Original file line number Diff line number Diff line change @@ -116,4 +116,21 @@ GROUP BY p
116
116
HAVING COUNT (1 ) >= 3 ;
117
117
```
118
118
119
+ ``` python
120
+ import pandas as pd
121
+
122
+
123
+ def consecutive_numbers (logs : pd.DataFrame) -> pd.DataFrame:
124
+ all_the_same = lambda lst : lst.nunique() == 1
125
+ logs[" is_consecutive" ] = (
126
+ logs[" num" ].rolling(window = 3 , center = True , min_periods = 3 ).apply(all_the_same)
127
+ )
128
+ return (
129
+ logs.query(" is_consecutive == 1.0" )[[" num" ]]
130
+ .drop_duplicates()
131
+ .rename(columns = {" num" : " ConsecutiveNums" })
132
+ )
133
+
134
+ ```
135
+
119
136
<!-- tabs:end -->
Original file line number Diff line number Diff line change @@ -112,4 +112,21 @@ GROUP BY p
112
112
HAVING COUNT (1 ) >= 3 ;
113
113
```
114
114
115
+ ``` python
116
+ import pandas as pd
117
+
118
+
119
+ def consecutive_numbers (logs : pd.DataFrame) -> pd.DataFrame:
120
+ all_the_same = lambda lst : lst.nunique() == 1
121
+ logs[" is_consecutive" ] = (
122
+ logs[" num" ].rolling(window = 3 , center = True , min_periods = 3 ).apply(all_the_same)
123
+ )
124
+ return (
125
+ logs.query(" is_consecutive == 1.0" )[[" num" ]]
126
+ .drop_duplicates()
127
+ .rename(columns = {" num" : " ConsecutiveNums" })
128
+ )
129
+
130
+ ```
131
+
115
132
<!-- tabs:end -->
Original file line number Diff line number Diff line change
1
+ import pandas as pd
2
+
3
+
4
+ def consecutive_numbers (logs : pd .DataFrame ) -> pd .DataFrame :
5
+ all_the_same = lambda lst : lst .nunique () == 1
6
+ logs ["is_consecutive" ] = (
7
+ logs ["num" ].rolling (window = 3 , center = True , min_periods = 3 ).apply (all_the_same )
8
+ )
9
+ return (
10
+ logs .query ("is_consecutive == 1.0" )[["num" ]]
11
+ .drop_duplicates ()
12
+ .rename (columns = {"num" : "ConsecutiveNums" })
13
+ )
You can’t perform that action at this time.
0 commit comments