TECHNOLOGIESTieInn Technologies

pandas basics: Series and DataFrames

Python · 15 questions

Short notes

Key idea

pandas gives you the DataFrame: a table with named columns and a row index. You load data, look at it, and select columns before doing anything clever.

Syntax

import pandas as pd
df = pd.read_csv("orders.csv")
df.head()          # first 5 rows
df.shape           # (rows, columns)
df.info()          # column types and non-null counts
df.describe()      # numeric summary
df["amount"]       # one column → Series
df[["city", "amount"]]   # several columns → DataFrame
df["amount"].mean()
df["city"].value_counts()

Example

df = pd.read_csv("orders.csv")
print(df.shape)
print(df["city"].value_counts().head(3))
print(round(df["amount"].mean(), 2))

Three lines tell you how big the data is, where orders come from and the average order.

Traps

  • One bracket gives a Series, two brackets a DataFrame.
  • Numbers read as text (because of a stray "N/A" or ₹ sign) show as object in info(); fix them before maths.
  • head() shows a sample, not the whole story. Check shape and info() too.
  • Most methods return a new DataFrame; assign the result or nothing changes.

Want the full lesson with step-by-step examples, a project and a certificate? Python course, ₹120 →

Questions

Open in Code Lab5 free questions
5 questions

    pandas basics: Series and DataFrames

  1. Question 1easy

    How do you get the number of rows and columns of a DataFrame df?

  2. pandas basics: Series and DataFrames

  3. Question 2easy

    What does customers["city"] return?

  4. pandas basics: Series and DataFrames

  5. Question 3easy

    What does this print?

    print(orders.shape[0])
  6. pandas basics: Series and DataFrames

  7. Question 4medium

    2 orders have no payment method. What does this print?

    print(orders["payment_method"].value_counts().sum())
  8. pandas basics: Series and DataFrames

  9. Question 5medium

    What does this print?

    print(customers["city"].nunique())

10 more questions on this topic, with hints, and tests

Sign up free for 21 days of every question and test.