← Back to Pandas Course | Chapter 3: DataFrame Basics | Lesson 7 of 7

Column के Data Types

हर column का एक dtype है, और सही dtype में convert करना memory बचाता है और गलत results रोकता है।

In this page:

  1. Column Data Types
Syntax
python
df.dtypes
df["column"].dtype

Column Data Types

dtypes हर column का type दिखाता है: int64, float64, object (text), bool, datetime64, और category। astype convert करता है, और pd.to_numeric या pd.to_datetime ज़्यादा control के साथ convert करते हैं। सही dtypes sorting, maths, और memory use को सही तरीके से behave कराते हैं।

Note: select_dtypes(include="number") सिर्फ numeric columns pick करता है।

उदाहरण: Column data types

python
import pandas as pd

df = pd.DataFrame({"id": ["1", "2", "3"], "price": ["9.5", "3.25", "7"]})
print(df.dtypes)
df["id"] = df["id"].astype(int)
df["price"] = pd.to_numeric(df["price"])
print(df.dtypes)
print(df.select_dtypes(include="number").columns.tolist())

# Output:
# id       object
# price    object
# dtype: object
# id         int64
# price    float64
# dtype: object
# ['id', 'price']
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. Numbers को text की तरह stored छोड़ना
  2. बिना clean किए commas वाला text convert करना
  3. यह भूल जाना कि astype एक नया object return करता है
चैप्टर सारांश
  • dtypes column types list करता है
  • astype convert करता है
  • to_numeric और to_datetime control add करते हैं
  • select_dtypes type से filter करता है
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.