"
import pandas as pd
def findaveragedistance(gps_data: pd.DataFrame) -> pd.DataFrame:
#0. IMPORTANT: get the unordered pairs
gpsdata['city1']=gpsdata[['origin','destination']].min(axis=1)
gpsdata['city2']=gpsdata[['origin','destination']].max(axis=1)
#1. get the mean distance by cities
avgdistance=gpsdata.groupby(['city1','city2'], as_index=False)['distance'].mean().round(2)
avgdistance.rename(columns={'distance':"averagedistance"}, inplace=True)
"
Sean L. - "
import pandas as pd
def findaveragedistance(gps_data: pd.DataFrame) -> pd.DataFrame:
#0. IMPORTANT: get the unordered pairs
gpsdata['city1']=gpsdata[['origin','destination']].min(axis=1)
gpsdata['city2']=gpsdata[['origin','destination']].max(axis=1)
#1. get the mean distance by cities
avgdistance=gpsdata.groupby(['city1','city2'], as_index=False)['distance'].mean().round(2)
avgdistance.rename(columns={'distance':"averagedistance"}, inplace=True)
"See full answer
"It depends on the size of the dataset. You want enough samples in both the testing, training and evaluation sets. If there is enough data, 70/20/10 is a good split"
Jasmine Y. - "It depends on the size of the dataset. You want enough samples in both the testing, training and evaluation sets. If there is enough data, 70/20/10 is a good split"See full answer
Coding
Data Structures & Algorithms
🧠 Want an expert answer to a question? Saving questions lets us know what content to make next.
"I might be missing something but the solution, seems to be incorrect.
...
, post_pairings AS (
SELECT
ps.user_id,
ps.postseqid AS failpostid,
ps.postseqid + 1 AS nextpostid
FROM post_seq AS ps
WHERE ps.issuccessfulpost IS TRUE
)
-- here ps.issuccessfulpost IS TRUE the condition should be FALSE
-- in that way ps.postseqid is the actual failed post(failpostid)
-- Additionally, at the end the join is assumming that the sequence id is going to match the post_id, wh"
Jaime A. - "I might be missing something but the solution, seems to be incorrect.
...
, post_pairings AS (
SELECT
ps.user_id,
ps.postseqid AS failpostid,
ps.postseqid + 1 AS nextpostid
FROM post_seq AS ps
WHERE ps.issuccessfulpost IS TRUE
)
-- here ps.issuccessfulpost IS TRUE the condition should be FALSE
-- in that way ps.postseqid is the actual failed post(failpostid)
-- Additionally, at the end the join is assumming that the sequence id is going to match the post_id, wh"See full answer
"Should this question be BST, not just BT? Otherwise it would not be possible to reconstruct the tree solely based on the array regardless of its order"
TreeOfWisdom - "Should this question be BST, not just BT? Otherwise it would not be possible to reconstruct the tree solely based on the array regardless of its order"See full answer
"public static void sortBinaryArray(int[] array) {
int len = array.length;
int[] res = new int[len];
int r=len-1;
for (int value : array) {
if(value==1){
res[r]= 1;
r--;
}
}
System.out.println(Arrays.toString(res));
}
`"
Nitin P. - "public static void sortBinaryArray(int[] array) {
int len = array.length;
int[] res = new int[len];
int r=len-1;
for (int value : array) {
if(value==1){
res[r]= 1;
r--;
}
}
System.out.println(Arrays.toString(res));
}
`"See full answer
"def validateIP(ip):
"""
@param ip: str
@return: bool
"""
\# ip needs to be in X.X.X.X
\# X is from 0 to 255
\# split the ip at "."
split = ip.split('.')
if (len(split) != 4):
return False
for number in split:
if (int(number) 255):
return False
return True"
Anonymous Owl - "def validateIP(ip):
"""
@param ip: str
@return: bool
"""
\# ip needs to be in X.X.X.X
\# X is from 0 to 255
\# split the ip at "."
split = ip.split('.')
if (len(split) != 4):
return False
for number in split:
if (int(number) 255):
return False
return True"See full answer
"Yes, I need to compare the first half of the first string with the reverse order of the second half of the second string. Repeat this process to the first half of the second string and the second half of the first string."
Anonymous Condor - "Yes, I need to compare the first half of the first string with the reverse order of the second half of the second string. Repeat this process to the first half of the second string and the second half of the first string."See full answer
"with my_table as (select *
, rownumber() over(order by customerid) as row_index
from customers)
select
customer_id,
customer_name
from my_table
where row_index % 3 = 0"
Marcos G. - "with my_table as (select *
, rownumber() over(order by customerid) as row_index
from customers)
select
customer_id,
customer_name
from my_table
where row_index % 3 = 0"See full answer
"Select
interface,
Count(case when issuccessfulpost then 1 end) as post_success,
Count() as postattempt,
ROUND((COUNT(CASE WHEN issuccessfulpost THEN 1 END) * 100 / COUNT()), 2) AS postsuccess_rate
from post where interface like 'Iphone%'
group by 1
order by postsuccessrate desc
`"
Richard B. - "Select
interface,
Count(case when issuccessfulpost then 1 end) as post_success,
Count() as postattempt,
ROUND((COUNT(CASE WHEN issuccessfulpost THEN 1 END) * 100 / COUNT()), 2) AS postsuccess_rate
from post where interface like 'Iphone%'
group by 1
order by postsuccessrate desc
`"See full answer
"-- Write your query here
With base as(
select
player_name
, team_id
, max(scores.gamescore) as gamescore
from players
join scores on players.playerid = scores.playerid
group by playername, teamid)
Select team_id
, player_name
, game_score
from (
Select teamid , playername ,gamescore, DenseRank() Over (Partition by teamid order by gamescore desc ) as rnk
from base) a where rnk <=2
`"
Palak S. - "-- Write your query here
With base as(
select
player_name
, team_id
, max(scores.gamescore) as gamescore
from players
join scores on players.playerid = scores.playerid
group by playername, teamid)
Select team_id
, player_name
, game_score
from (
Select teamid , playername ,gamescore, DenseRank() Over (Partition by teamid order by gamescore desc ) as rnk
from base) a where rnk <=2
`"See full answer