تعديل المحتوى الموضوع * -- اختر موضوع --C# CourseCSSHTMLJava ScriptPython Fundamentals اساسياتSQL Serverرواية الفيل الأزرقمواضيع متنوعة الوحدة * -- اختر وحدة --1. الوحدة 1: الانطلاقة (1)2. الوحدة 2: الأساسيات (2)3. الوحدة 3: التحكم في مسار البرنامج (3)4. الوحدة 4: هياكل البيانات (4)5. الوحدة 5: الدوال وتنظيم الكود (5)6. الوحدة 6: الملفات والمدخلات والمخرجات (6)7. الوحدة 7: البرمجة الكائنية OOP (7)8. الوحدة 8: مكتبات Python الأساسية (8)9. الوحدة 9: مقدمة تحليل البيانات (9) ترتيب الدرس ترتيب ظهور الدرس داخل الوحدة عنوان المحتوى * محتوى الدرس * (12199 حرف) <!DOCTYPE html> <html lang="ar" dir="rtl"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>الدرس 9.2: مقدمة في Pandas — السلاسل Series</title> <script src="https://cdn.tailwindcss.com"></script> <link href="https://fonts.googleapis.com/css2?family=Tajawal:wght@300;400;700;800&display=swap" rel="stylesheet"> <style> body { font-family: 'Tajawal', sans-serif; background-color: #f8fafc; color: #1e293b; } .section-card { background: white; border-radius: 1rem; box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06); padding: 2rem; margin-bottom: 2rem; border-right: 5px solid #10b981; } .icon-box { display: inline-flex; align-items: center; justify-content: center; width: 3rem; height: 3rem; border-radius: 0.5rem; margin-left: 0.75rem; font-size: 1.7rem; } /* Code Block */ .code-block { position: relative; background-color: #1e293b; color: #e2e8f0; border-radius: 0.75rem; padding: 1.5rem; font-family: 'Courier New', monospace; overflow-x: auto; direction: ltr; text-align: left; margin-top: 1rem; white-space: pre; font-size: 1.1rem; border: 2px solid #0f172a; } .copy-btn { position: absolute; top: 0.5rem; right: 0.5rem; background-color: #334155; color: white; border: 1px solid #475569; padding: 0.3rem 0.9rem; border-radius: 0.25rem; font-size: 0.85rem; cursor: pointer; } .copy-btn:hover { background-color: #475569; } .copy-btn.copied { background-color: #10b981; border-color: #10b981; } /* Try Button */ .try-btn { margin-top: 0.5rem; background-color: #10b981; color: white; padding: 0.55rem 1.2rem; border-radius: 0.45rem; font-size: 0.95rem; font-weight: 700; display: inline-block; cursor: pointer; transition: 0.2s; box-shadow: 0 3px 5px rgba(16, 185, 129, 0.22); } .try-btn:hover { background-color: #059669; transform: translateY(-1px); } /* Syntax Highlighting */ .py-comment { color:#94a3b8; font-style:italic; } .py-str { color:#4ade80; } .py-func { color:#60a5fa; } .py-num { color:#facc15; } .py-import { color:#a5b4fc; font-weight:bold; } </style> </head> <body> <div class="p-4 md:p-8 max-w-6xl mx-auto"> <!-- Header --> <header class="text-center mb-12"> <h1 class="text-4xl md:text-5xl font-extrabold text-green-700 mb-4"> الدرس 9.2: مقدمة في Pandas — السلاسل Series </h1> <p class="text-2xl text-gray-600"> الخطوة الأولى نحو تحليل البيانات باستخدام مكتبة Pandas </p> </header> <!-- Section 1: مقدمة Pandas --> <section class="section-card"> <h2 class="text-3xl font-bold mb-6 flex items-center"> <span class="icon-box bg-green-100 text-green-700">📊</span> ما هي Pandas؟ </h2> <p class="text-xl text-gray-700 mb-4"> مكتبة <strong>Pandas</strong> هي واحدة من أهم المكتبات في عالم تحليل البيانات، وتوفر هياكل بيانات قوية وسهلة الاستخدام. تعتمد Pandas أساسًا على مكتبة <strong>NumPy</strong>، لكن تضيف عليها أدوات أكثر ملاءمة للتعامل مع البيانات مثل الجداول (DataFrames) والسلاسل (Series). </p> <p class="text-xl text-gray-700"> السلسلة <strong>Series</strong> هي الخطوة الأولى لفهم Pandas، وهي عبارة عن: <br> <strong>قائمة بيانات أحادية البعد (مثل عمود واحد)، ولكل عنصر قيمة + اسم فهرس (index)</strong>. </p> <p class="text-xl text-gray-700 mt-4"> تثبيت Pandas: <br> <code>pip install pandas</code> </p> </section> <!-- Section 2: إنشاء Series --> <section class="section-card" style="border-right-color:#0ea5e9;"> <h2 class="text-3xl font-bold mb-6 flex items-center"> <span class="icon-box bg-blue-100 text-blue-700">🧱</span> إنشاء أول Series </h2> <p class="text-xl text-gray-700 mb-4"> يمكن إنشاء Series من قائمة Python بسهولة: </p> <div class="code-block"> <button class="copy-btn" onclick="copyCode('series-basic', this)">نسخ</button> <code id="series-basic"> <span class="py-import">import</span> pandas <span class="py-func">as</span> pd data = [<span class="py-num">10</span>, <span class="py-num">20</span>, <span class="py-num">30</span>, <span class="py-num">40</span>] s = pd.Series(data) <span class="py-func">print</span>(s) </code> </div> <button class="try-btn" onclick="runCode('series-basic')">▶️ تجربة الكود</button> <p class="text-xl text-gray-700 mt-4"> لاحظ أن Pandas يضيف فهرسًا تلقائيًا يبدأ من 0، تمامًا كما تفعل القوائم. </p> </section> <!-- Section 3: تعيين فهرس مخصص --> <section class="section-card" style="border-right-color:#f97316;"> <h2 class="text-3xl font-bold mb-6 flex items-center"> <span class="icon-box bg-orange-100 text-orange-700">🏷️</span> تخصيص الفهرس (Index) </h2> <p class="text-xl text-gray-700 mb-4"> يمكنك إعطاء أسماء مخصصة للفهرس بدل الأرقام: </p> <div class="code-block"> <button class="copy-btn" onclick="copyCode('series-index', this)">نسخ</button> <code id="series-index"> <span class="py-import">import</span> pandas <span class="py-func">as</span> pd data = [<span class="py-num">90</span>, <span class="py-num">85</span>, <span class="py-num">78</span>] index = [<span class="py-str">"Ali"</span>, <span class="py-str">"Sara"</span>, <span class="py-str">"Omar"</span>] scores = pd.Series(data, index=index) <span class="py-func">print</span>(scores) </code> </div> <button class="try-btn" onclick="runCode('series-index')">▶️ تجربة الكود</button> <p class="text-xl text-gray-700 mt-4"> هذا يجعل السلسلة أكثر وضوحًا — مثل جدول نتائج الطلاب. </p> </section> <!-- Section 4: الوصول للعناصر --> <section class="section-card" style="border-right-color:#6366f1;"> <h2 class="text-3xl font-bold mb-6 flex items-center"> <span class="icon-box bg-indigo-100 text-indigo-700">🎯</span> الوصول للعناصر باستخدام index أو الشرائح </h2> <div class="code-block"> <button class="copy-btn" onclick="copyCode('series-access', this)">نسخ</button> <code id="series-access"> <span class="py-import">import</span> pandas <span class="py-func">as</span> pd s = pd.Series([<span class="py-num">100</span>, <span class="py-num">200</span>, <span class="py-num">300</span>], index=[<span class="py-str">"A"</span>, <span class="py-str">"B"</span>, <span class="py-str">"C"</span>]) <span class="py-comment"># الوصول باستخدام الفهرس</span> <span class="py-func">print</span>(s[<span class="py-str">"A"</span>]) <span class="py-comment"># الوصول باستخدام الشرائح (مثل القوائم)</span> <span class="py-func">print</span>(s[<span class="py-num">0</span>:<span class="py-num">2</span>]) </code> </div> <button class="try-btn" onclick="runCode('series-access')">▶️ تجربة الكود</button> </section> <!-- Section 5: العمليات الرياضية --> <section class="section-card" style="border-right-color:#8b5cf6;"> <h2 class="text-3xl font-bold mb-6 flex items-center"> <span class="icon-box bg-purple-100 text-purple-700">➕</span> العمليات الرياضية على Series </h2> <p class="text-xl text-gray-700 mb-4"> Pandas تعتمد على NumPy، لذلك يمكن إجراء العمليات الحسابية بسهولة على كامل السلسلة: </p> <div class="code-block"> <button class="copy-btn" onclick="copyCode('series-ops', this)">نسخ</button> <code id="series-ops"> <span class="py-import">import</span> pandas <span class="py-func">as</span> pd s = pd.Series([<span class="py-num">10</span>, <span class="py-num">20</span>, <span class="py-num">30</span>]) <span class="py-comment"># جمع رقم مع السلسلة</span> <span class="py-func">print</span>(s + <span class="py-num">5</span>) <span class="py-comment"># ضرب</span> <span class="py-func">print</span>(s * <span class="py-num">2</span>) <span class="py-comment"># دوال إحصائية</span> <span class="py-func">print</span>(s.mean()) <span class="py-comment"># متوسط</span> <span class="py-func">print</span>(s.max()) <span class="py-comment"># أكبر قيمة</span> </code> </div> <button class="try-btn" onclick="runCode('series-ops')">▶️ تجربة الكود</button> </section> <!-- Section 6: تحويل القواميس إلى Series --> <section class="section-card" style="border-right-color:#fb7185;"> <h2 class="text-3xl font-bold mb-6 flex items-center"> <span class="icon-box bg-pink-100 text-pink-700">📚</span> تحويل القواميس إلى Series </h2> <p class="text-xl text-gray-700 mb-4"> القواميس مناسبة جدًا للتحويل إلى Series لأن المفتاح يصبح فهرسًا: </p> <div class="code-block"> <button class="copy-btn" onclick="copyCode('series-dict', this)">نسخ</button> <code id="series-dict"> <span class="py-import">import</span> pandas <span class="py-func">as</span> pd students = { <span class="py-str">"Ali"</span>: <span class="py-num">90</span>, <span class="py-str">"Mona"</span>: <span class="py-num">88</span>, <span class="py-str">"Omar"</span>: <span class="py-num">79</span> } s = pd.Series(students) <span class="py-func">print</span>(s) </code> </div> <button class="try-btn" onclick="runCode('series-dict')">▶️ تجربة الكود</button> </section> <!-- Section 7: تمرين --> <section class="section-card" style="border-right-color:#ec4899;"> <h2 class="text-3xl font-bold mb-6 flex items-center"> <span class="icon-box bg-pink-100 text-pink-700">🧪</span> تمرين عملي (مرقّم) </h2> <div class="bg-pink-50 p-6 rounded-lg border border-pink-200"> <h3 class="text-pink-900 font-bold mb-4 text-2xl">المطلوب منك:</h3> <ol class="space-y-4 text-gray-700 text-xl list-decimal pr-6"> <li> أنشئ Series تمثل درجات 5 طلاب من اختيارك. </li> <li> عيّن فهرسًا مخصصًا يمثل أسماء الطلاب. </li> <li> احسب: <ul class="list-disc pr-6 mt-2"> <li>متوسط الدرجات</li> <li>أعلى درجة</li> <li>أقل درجة</li> </ul> </li> <li> اختر طالبًا باستخدام الفهرس واطبع درجته. </li> <li> أنشئ Series جديدة من قاموس يحتوي على: <br> اسم المنتج → السعر <br> ثم أضف 10% إلى كل الأسعار باستخدام العمليات الحسابية. </li> </ol> </div> </section> <footer class="text-center text-gray-400 text-lg mt-8 pb-8"> الدرس 9.2 — مقدمة في Pandas — السلاسل Series </footer> </div> <script> function copyCode(elementId, btnElement=null) { const text = document.getElementById(elementId).innerText; const textarea = document.createElement('textarea'); textarea.value = text; document.body.appendChild(textarea); textarea.select(); document.execCommand('copy'); textarea.remove(); if (btnElement) { const original = btnElement.innerText; btnElement.innerText = "تم النسخ!"; btnElement.classList.add('copied'); setTimeout(() => { btnElement.innerText = original; btnElement.classList.remove('copied'); }, 1200); } } function runCode(elementId) { copyCode(elementId); window.open("/python/trypython", "_blank"); } </script> </body> </html> حفظ إلغاء حفظ وإضافة جديد