Skip to content

Commit 43951cc

Browse files
authored
Create Web-user.py
Add Web-user.py for PySpark and update contributors list This pull request adds the Web-user.py script for PySpark functionality and includes myself (divith raju) in the contributors list.
1 parent a5f0ded commit 43951cc

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

Web-user.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Find the count of unique visitors to a website per day.
2+
3+
from pyspark.sql import SparkSession, Row
4+
from pyspark.sql.functions import countDistinct
5+
6+
# Initialize Spark session
7+
spark = SparkSession.builder.appName("UniqueVisitorsPerDay").getOrCreate()
8+
9+
# Sample data
10+
visitor_data = [Row(Date='2023-01-01', VisitorID=101),
11+
Row(Date='2023-01-01', VisitorID=102),
12+
Row(Date='2023-01-01', VisitorID=101),
13+
Row(Date='2023-01-02', VisitorID=103),
14+
Row(Date='2023-01-02', VisitorID=101)]
15+
16+
# Create DataFrame
17+
df_visitors = spark.createDataFrame(visitor_data)
18+
19+
# Count unique visitors per day
20+
unique_visitors = df_visitors.groupBy('Date').agg(countDistinct('VisitorID').alias('UniqueVisitors'))
21+
22+
# Show results
23+
unique_visitors.show()

0 commit comments

Comments
 (0)