और डेटा जुटाना

PySpark के साथ Feature Engineering

John Hogue

Lead Data Scientist, General Mills

बाहरी डेटा सेट पर विचार

फायदे

  • अहम predictors जोड़ें
  • मान पूरक करें/बदलेँ
  • पाना सस्ता या आसान

डेटा मिलाना

नुकसान

  • विश्लेषण धीमा पड़ सकता है
  • डेटा leakage कराना आसान
  • डेटा सेट के विषय-वस्तु विशेषज्ञ बनें

जिम्मेदारी

PySpark के साथ Feature Engineering

Joins के बारे में

हमारे डेटा की दिशा तय करना

  • बाएँ: हमारा शुरुआती डेटा सेट
  • दाएँ: जोड़ने वाला नया डेटा सेट

SQL Joins

PySpark के साथ Feature Engineering

PySpark DataFrame Joins

DataFrame.join(

other, # Other DataFrame to merge
on=None, # The keys to join on
how=None) # Type of join to perform (default is 'inner')
PySpark के साथ Feature Engineering

PySpark Join उदाहरण

# Inspect dataframe head
hdf.show(2)
+----------+--------------------+
|        dt|                  nm|
+----------+--------------------+
|2012-01-02|        New Year Day|
|2012-01-16|Martin Luther Kin...|
+----------+--------------------+
only showing top 2 rows
# Specify join conditon
cond = [df['OFFMARKETDATE'] == hdf['dt']]

# Join two hdf onto df df = df.join(hdf, on=cond, 'left')
# How many sales occurred on bank holidays? df.where(~df['nm'].isNull()).count()
0
PySpark के साथ Feature Engineering

SparkSQL Join

  • अपने dataframe पर SQL लागू करें
# Register the dataframe as a temp table
df.createOrReplaceTempView("df")
hdf.createOrReplaceTempView("hdf")
# Write a SQL Statement
sql_df = spark.sql("""
                      SELECT 
                        *
                      FROM df
                      LEFT JOIN hdf
                      ON df.OFFMARKETDATE = hdf.dt
                   """)
PySpark के साथ Feature Engineering

आइए कुछ डेटा Join करें!

PySpark के साथ Feature Engineering

Preparing Video For Download...