Answers for "drop duplicate"

0

Return a new DataFrame with duplicate rows removed

# Return a new DataFrame with duplicate rows removed

from pyspark.sql import Row
df = sc.parallelize([
  Row(name='Alice', age=5, height=80),
  Row(name='Alice', age=5, height=80),
  Row(name='Alice', age=10, height=80)]).toDF()
df.dropDuplicates().show()
# +---+------+-----+
# |age|height| name|
# +---+------+-----+
# |  5|    80|Alice|
# | 10|    80|Alice|
# +---+------+-----+

df.dropDuplicates(['name', 'height']).show()
# +---+------+-----+
# |age|height| name|
# +---+------+-----+
# |  5|    80|Alice|
# +---+------+-----+
Posted by: Guest on April-08-2020
0

droping Duplicates

# this is based on 2 factors the name of the dog and the breed of the dog so we can
# have 2 dog with the same name but diff breed.

df.drop_duplicates(subset=["name", "breed"])
Posted by: Guest on November-06-2021
0

Remove Duplicates

String -- Remove Duplicates
Write a return method that can remove the duplicated values from String
Ex:  removeDup("AAABBBCCC")  ==> ABC

USING CORE JAVA
Public static void main(String[] args){
	removeDup(“AAABBBCCC”).sout;
}

public static  String  removeDup( String  str) {
String result = "";
    for (int i = 0; i < str.length(); i++)
        if (!result.contains("" + str.charAt(i)))
        result += "" + str.charAt(i);
 
    return result;
}
 
USING LINKED HASH SET
Public static void main(String[] args){
	removeDup(“AAABBBCCC”).sout;
}

public static String removeDup(String str) {
str = new LinkedHashSet<String>(Arrays.asList(str.split(""))).toString();
str = str.replace(", " ,  "" ).replace("[","").replace("]","");
    return  str;
}
Posted by: Guest on September-29-2021
-1

remove duplicate

let ageGroup = [18, 21, 1, 1, 51, 18, 21, 5, 18, 7, 10];
let uniqueAgeGroup = ageGroup.reduce(function (accumulator, currentValue) {
  if (accumulator.indexOf(currentValue) === -1) {
    accumulator.push(currentValue);
  }
  return accumulator;
}, []);

console.log(uniqueAgeGroup); // [ 18, 21, 1, 51, 5, 7, 10 ]
Posted by: Guest on June-25-2021

Python Answers by Framework

Browse Popular Code Answers by Language