Schema लिखना
हमने अब तक कई तरीकों से Schemas लोड किए हैं. तो चलिए सीधे एक schema परिभाषित करते हैं. हम एक डेटा डिक्शनरी का उपयोग करेंगे:
| Variable | Description |
|---|---|
| age | व्यक्ति की आयु |
| education_num | डिग्री के आधार पर शिक्षा |
| marital_status | वैवाहिक स्थिति |
| occupation | पेशा |
| income | श्रेणीबद्ध आय |
यह अभ्यास पाठ्यक्रम का हिस्सा है
PySpark परिचय
अभ्यास निर्देश
- डेटा schema निर्दिष्ट करें: कॉलम नाम (
age,education_num,marital_status,occupation, औरincome) और उनके types दें, औरsep=आर्गुमेंट में comma सेट करें. adult_reduced_100.csvनाम की comma-delimited फ़ाइल से डेटा पढ़ें.- बने हुए DataFrame के लिए schema प्रिंट करें.
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
from pyspark.sql.types import StructType, StructField, IntegerType, StringType
# Fill in the schema with the columns you need from the exercise instructions
schema = StructType([____("____",____()),
____("____",____()),
____("marital_status",StringType()),
StructField("____",____()),
____("____",____()),
])
# Read in the CSV, using the schema you defined above
census_adult = spark.read.csv("adult_reduced_100.csv", sep='____', header=False, schema=schema)
# Print out the schema
census_adult.____