How to perform a word count on a dataframe column?

0 votes

I have created a dataframe of two columns id and text, I want to perform a wordcount on the text column of the dataframe. What code can I use to do this using PySpark?

Jan 22 in Big Data Hadoop by Karan
45 views

1 answer to this question.

0 votes

You can use the below code to do this:

rdd=sc.textfile(inputfile)

wc=rdd.flatMap(lambda line: line.split()).map(lambda w : (w,1)).reduceByKey(lambda a,b:a+b).map(lambda (a,b) : (b,a)).sortByKey(ascending=True)

output=sc.collect()


for (count, word) in output:

       print("%s %i",(word, count))
answered Jan 22 by Omkar
• 67,520 points

Related Questions In Big Data Hadoop

0 votes
1 answer

How to count lines in a file on hdfs command?

Use the below commands: Total number of files: hadoop ...READ MORE

answered Aug 10, 2018 in Big Data Hadoop by Neha
• 6,280 points
2,852 views
0 votes
1 answer

How to groupBy/count then filter on count in Scala

I think the exception is caused because ...READ MORE

answered Apr 19, 2018 in Big Data Hadoop by kurt_cobain
• 9,240 points
6,787 views
0 votes
1 answer

How to add column inside a table in Hive?

Hi, Yes, we can add column inside a ...READ MORE

answered May 15 in Big Data Hadoop by Gitika
• 25,340 points
27 views
0 votes
1 answer

How to Change the maximum number of cells of a column family?

Hey, Given below is the syntax to change ...READ MORE

answered May 24 in Big Data Hadoop by Gitika
• 25,340 points
20 views
0 votes
1 answer

Hadoop Mapreduce word count Program

Firstly you need to understand the concept ...READ MORE

answered Mar 16, 2018 in Data Analytics by nitinrawat895
• 10,670 points
2,756 views
0 votes
1 answer

hadoop.mapred vs hadoop.mapreduce?

org.apache.hadoop.mapred is the Old API  org.apache.hadoop.mapreduce is the ...READ MORE

answered Mar 16, 2018 in Data Analytics by nitinrawat895
• 10,670 points
289 views
0 votes
10 answers

hadoop fs -put command?

put syntax: put <localSrc> <dest> copy syntax: copyFr ...READ MORE

answered Dec 7, 2018 in Big Data Hadoop by Aditya
13,633 views
0 votes
1 answer

Hadoop dfs -ls command?

In your case there is no difference ...READ MORE

answered Mar 16, 2018 in Big Data Hadoop by kurt_cobain
• 9,240 points
1,001 views
0 votes
1 answer

How to embed HDFS cluster information on a website?

Hi @Bhavish.  It is possible to get cluster ...READ MORE

answered May 27 in Big Data Hadoop by Omkar
• 67,520 points
33 views
+1 vote
1 answer

How to count number of rows in alias in PIG?

COUNT is part of pig LOGS= LOAD 'log'; LOGS_GROUP= ...READ MORE

answered Oct 15, 2018 in Big Data Hadoop by Omkar
• 67,520 points
88 views