Python / Data Science Essentials Interview Questions
What is a Pandas DataFrame and how does it differ from a NumPy array?
A Pandas DataFrame is a two-dimensional, labelled data structure — think of it as a spreadsheet or a SQL table in memory. Rows and columns both have labels (the index and the column names), and each column can hold a different data type. A Series is the single-column equivalent.
| Feature | NumPy ndarray | Pandas DataFrame |
|---|---|---|
| Dimensions | N-dimensional | Always 2-D (rows × columns) |
| Data type | Single dtype per array | Each column has its own dtype |
| Labels | Integer positions only | Named row index + column headers |
| Missing values | No native support (use np.nan) | First-class NaN / NaT / pd.NA |
| Primary use | Numerical computation | Tabular data: ETL, analysis, SQL-like ops |
import pandas as pd
import numpy as np
df = pd.DataFrame({
'name': ['Alice', 'Bob', 'Carol'],
'age': [30, 25, 35],
'salary': [95000.0, 72000.0, np.nan],
})
print(df.dtypes)
# name object
# age int64
# salary float64
print(df.shape) # (3, 3)
print(df.index) # RangeIndex(start=0, stop=3, step=1)
print(df.columns) # Index(['name', 'age', 'salary'], dtype='object')DataFrames are built on top of NumPy arrays — each column is essentially a NumPy array wrapped with extra metadata. When computation speed is paramount you often drop down to df.values or df.to_numpy() to get the raw array and run NumPy operations on it.
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
