بناء DataFrame من الصفر
من القواميس والقوائم والمصفوفات
بناء DataFrame من الصفر درس مجاني في Data Science Academy على CoddyKit. هذا هو الدرس 2 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Data Science Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Data Science Academy 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
Why Build Your Own
Before loading real files, building a small DataFrame by hand lets you test ideas and learn the structure with zero setup. 🧪
Import pandas First
Every project starts the same way: import pandas under the nickname pd. That short alias is a universal convention you will see everywhere.
import pandas as pdFrom a Dictionary of Columns
The most common recipe is a dict where each key is a column name and each value is a list of that column's data.
df = pd.DataFrame({"name": ["Ada", "Lin"], "age": [36, 41]})Keys Become Headers
With the dict approach, the dictionary keys turn into your column headers automatically. Naming columns is as easy as naming keys.
From a List of Rows
You can also pass a list of rows and supply the column names separately. Handy when your data already arrives row by row.
pd.DataFrame([["Ada", 36], ["Lin", 41]], columns=["name", "age"])From a List of Dicts
A list of dicts works too, with one dict per row. Missing keys simply become blanks, which is great for uneven records.
pd.DataFrame([{"name": "Ada"}, {"name": "Lin", "age": 41}])From a NumPy Array
Have a NumPy array of numbers? Pass it straight in and add column names. This bridges fast NumPy math with labeled tables.
pd.DataFrame(arr, columns=["x", "y"])Set the Index on Creation
Pass an index argument to label your rows the moment you build the frame, instead of relying on default 0, 1, 2 numbers.
pd.DataFrame(data, index=["r1", "r2"])Control the Column Order
Want columns in a specific order? Pass a columns list and pandas arranges them exactly as you list, ignoring dict ordering quirks.
pd.DataFrame(data, columns=["age", "name"])Lengths Must Match
Every column you provide must have the same length. Mismatched list sizes raise an error, so keep your columns even.
Peek at What You Built
After building, glance at dtypes to confirm pandas inferred sensible types like int for ages and object for names.
df.dtypesQuick Check
Pick the building block behind the most common DataFrame recipe.
Recap: Many Ways In
Dicts, lists, list-of-dicts, or NumPy arrays all become a DataFrame. Pick whatever matches the shape of your data. 🛠️
الأسئلة الشائعة
هل درس «بناء DataFrame من الصفر» مجاني؟
نعم — نص درس «بناء DataFrame من الصفر» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Data Science Academy، انتقل إلى CoddyKit PRO. تتضمن دورة Data Science Academy 4 دروس في المجموع.
ماذا ستتعلم في «بناء DataFrame من الصفر»؟
من القواميس والقوائم والمصفوفات تتمرن على Data Science Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ Data Science Academy؟
لا تُشترط خبرة سابقة. Data Science Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 2 من أصل 4.
كم من الوقت يستغرق درس «بناء DataFrame من الصفر»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس Data Science Academy هذا؟
نعم. كل درس في Data Science Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- الصفوف والأعمدة والفهرس
- بناء DataFrame من الصفر
- head وinfo وdescribe
- إضافة الأعمدة وإعادة تسميتها وحذفها