استخراج السنة والشهر ويوم الأسبوع
استخدام موصّل dt لإنشاء الميزات
استخراج السنة والشهر ويوم الأسبوع درس مجاني في Data Science Academy على CoddyKit. هذا هو الدرس 2 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Data Science Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Data Science Academy 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
A Timestamp Holds a Lot
One datetime value packs a year, month, day, hour, and weekday inside it. The skill is pulling each piece out as its own column for analysis. 🧩
Meet the dt Accessor
On a datetime column, the dt accessor is your gateway. It exposes every date part as a simple attribute you can read or assign.
df["date"].dt # gateway to date partsPull Out the Year
Grabbing the year is one line. It is perfect for grouping sales or events into annual buckets.
df["year"] = df["date"].dt.yearMonth as a Number
The month attribute returns 1 through 12. Use it to compare the same month across different years.
df["month"] = df["date"].dt.monthMonth by Name
Numbers are fine for sorting, but charts read better with names. Use month_name to get January, February, and friends.
df["date"].dt.month_name() # 'March'Day of the Week
The dayofweek attribute numbers days from Monday=0 to Sunday=6. It is the backbone of any weekday analysis.
df["dow"] = df["date"].dt.dayofweekWeekday by Name
Want readable labels instead? Use day_name to turn each date into Monday, Tuesday, and so on for clean grouping.
df["date"].dt.day_name() # 'Friday'Spot the Weekend
Combine dayofweek with a comparison to flag weekends. This boolean column instantly splits work days from rest days.
df["weekend"] = df["date"].dt.dayofweek >= 5Quarter and Day of Year
Two more handy parts: quarter for Q1 to Q4 reporting, and dayofyear for tracking position within a single year.
df["date"].dt.quarter
df["date"].dt.dayofyearHours and Minutes Too
If your data has time, the dt accessor also exposes hour and minute. That makes it easy to study peak activity windows.
df["hour"] = df["date"].dt.hourFeatures Power Analysis
Each extracted part becomes a feature you can group by or feed to a model. This is how raw timestamps turn into insight.
df.groupby(df["date"].dt.month).size()Quick Check
You want to flag rows that fall on Saturday or Sunday.
Recap: Unpack Any Date
You used the dt accessor to pull year, month, weekday, quarter, and hour from timestamps, turning each into a feature ready for grouping. 🗓️
الأسئلة الشائعة
هل درس «استخراج السنة والشهر ويوم الأسبوع» مجاني؟
نعم — نص درس «استخراج السنة والشهر ويوم الأسبوع» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Data Science Academy، انتقل إلى CoddyKit PRO. تتضمن دورة Data Science Academy 4 دروس في المجموع.
ماذا ستتعلم في «استخراج السنة والشهر ويوم الأسبوع»؟
استخدام موصّل dt لإنشاء الميزات تتمرن على Data Science Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ Data Science Academy؟
لا تُشترط خبرة سابقة. Data Science Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 2 من أصل 4.
كم من الوقت يستغرق درس «استخراج السنة والشهر ويوم الأسبوع»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس Data Science Academy هذا؟
نعم. كل درس في Data Science Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- تحليل السلاسل إلى Datetimes
- استخراج السنة والشهر ويوم الأسبوع
- إعادة أخذ العينات يوميًا أو شهريًا
- المناطق الزمنية ونطاقات التاريخ