تحليل التواريخ وتعيين dtypes عند التحميل
ضبط الأنواع وقت الاستيراد
تحليل التواريخ وتعيين dtypes عند التحميل درس مجاني في Data Science Academy على CoddyKit. هذا هو الدرس 3 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Data Science Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Data Science Academy 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
Types Matter From the Start
When pandas reads a file it guesses each column's dtype. Get types right at load time and every later step gets simpler. 🧱
Dates Arrive as Text
A date like 2024-03-01 looks like a date to you, but pandas reads it as a plain string unless you ask otherwise.
Parse Dates on Load
The parse_dates option converts listed columns into real datetime values during the read, no extra step needed.
df = pd.read_csv("sales.csv",
parse_dates=["order_date"])Why It Pays Off
Once a column is a real datetime, you can sort by time, filter date ranges, and pull out the month with ease.
Help With Odd Formats
For unusual layouts, pass a format string so pandas parses fast and never guesses wrong on day-month order.
df = pd.read_csv("eu.csv",
parse_dates=["d"], date_format="%d/%m/%Y")Force Specific dtypes
The dtype option lets you declare a column's type yourself, overriding pandas guesses with a clean dictionary.
df = pd.read_csv("data.csv",
dtype={"zip": "string"})Keep Leading Zeros
Codes like 00123 lose their zeros if read as numbers. Forcing the column to string preserves them exactly as written.
df = pd.read_csv("ids.csv",
dtype={"product_code": str})Shrink Memory With Types
Reading whole numbers as int32 instead of the default int64 can halve memory on big files. Choose the smallest type that fits.
df = pd.read_csv("big.csv",
dtype={"count": "int32"})Repeated Text? Use category
Columns with few repeated values, like a status field, shrink dramatically when stored as the category dtype.
df = pd.read_csv("orders.csv",
dtype={"status": "category"})Verify After Loading
Always confirm the result. Checking dtypes shows exactly how pandas typed each column so surprises never reach your analysis.
print(df.dtypes)Fix Types Later If Needed
Missed one? You can still convert afterward with astype, but doing it at load is cleaner and a little faster.
df["count"] = df["count"].astype("int32")Quick Check
A column of dates is loading as plain text. What fixes it during read?
Recap: Right Types, Less Pain
You can now parse dates, force string and numeric types, and use category for repeats, all at load time. Verify with dtypes and move on. 🎉
الأسئلة الشائعة
هل درس «تحليل التواريخ وتعيين dtypes عند التحميل» مجاني؟
نعم — نص درس «تحليل التواريخ وتعيين dtypes عند التحميل» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Data Science Academy، انتقل إلى CoddyKit PRO. تتضمن دورة Data Science Academy 4 دروس في المجموع.
ماذا ستتعلم في «تحليل التواريخ وتعيين dtypes عند التحميل»؟
ضبط الأنواع وقت الاستيراد تتمرن على Data Science Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ Data Science Academy؟
لا تُشترط خبرة سابقة. Data Science Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 3 من أصل 4.
كم من الوقت يستغرق درس «تحليل التواريخ وتعيين dtypes عند التحميل»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس Data Science Academy هذا؟
نعم. كل درس في Data Science Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- read_csv وخياراته المفيدة
- فتح أوراق Excel في pandas
- تحليل التواريخ وتعيين dtypes عند التحميل
- حفظ النتائج إلى CSV وExcel