PySpark परिचय
Benjamin Schmidt
Data Engineer
spark.read.csv("path/to/file.csv")
spark.read.json("path/to/file.json")
spark.read.parquet("path/to/file.parquet")
Spark inferSchema=True से डेटा से स्कीमा अपने-आप निकाल सकता है
बेहतर नियंत्रण के लिए स्कीमा मैन्युअली परिभाषित करें - फिक्स्ड डेटा स्ट्रक्चर में उपयोगी

IntegerType: पूर्णांक संख्याएँ1, 3478, -18904569223347758063.14159"This is an example of a string."# आवश्यक टाइप्स को क्लास के रूप में इम्पोर्ट करें
from pyspark.sql.types import (StructType,
StructField, IntegerType,
StringType, ArrayType)
# स्कीमा बनाएँ
schema = StructType([
StructField("id", IntegerType(), True),
StructField("name", StringType(), True),
StructField("scores", ArrayType(IntegerType()), True)
])
# स्कीमा सेट करें
df = spark.createDataFrame(data, schema=schema)
.select() इस्तेमाल करें.filter() या .where() इस्तेमाल करें.sort() इस्तेमाल करें# सिर्फ name और age कॉलम चुनें और दिखाएँ
df.select("name", "age").show()
# age > 30 पर फ़िल्टर करें
df.filter(df["age"] > 30).show()
# किसी खास मान पर फ़िल्टर करने के लिए where का प्रयोग
df.where(df["age"] == 30).show()
# age पर सॉर्ट करें
df.sort("age", ascending=False).show()
.sort() या .orderBy() से डेटा ऑर्डर करेंna.drop() से null मान वाली पंक्तियाँ हटाएँ# age कॉलम से सॉर्ट करें
df.sort("age", ascending=False).show()
# मिसिंग वैल्यू हटाएँ
df.na.drop().show()
spark.read_json(): JSON से डेटा लोड करेंspark.read.schema(): स्कीमा स्पष्ट रूप से परिभाषित करें.na.drop(): मिसिंग वैल्यू वाली पंक्तियाँ हटाएँ.select(), .filter(), .sort(), .orderBy(): बेसिक डेटा मैनिपुलेशन फंक्शनPySpark परिचय