1. What is Python and why is it popular for data analysis?
Python is a high-level, interpreted programming language known for simplicity and readability. It’s popular in data analysis due to its rich ecosystem of libraries like Pandas, NumPy, and Matplotlib that simplify data manipulation, analysis, and visualization.2. Differentiate between lists, tuples, and sets in Python.
⦁ List: Mutable, ordered, allows duplicates.
⦁ Tuple: Immutable, ordered, allows duplicates.
⦁ Set: Mutable, unordered, no duplicates.
3. How do you handle missing data in a dataset?
Common methods: removing rows/columns with missing values, filling with mean/median/mode, or using interpolation. Libraries like Pandas provide
.dropna(), .fillna() functions to do this easily.4. What are list comprehensions and how are they useful?
Concise syntax to create lists from iterables using a single readable line, often replacing loops for cleaner and faster code.
Example:
[x**2 for x in range(5)] → ``5. Explain Pandas DataFrame and Series.
⦁ Series: 1D labeled array, like a column.
⦁ DataFrame: 2D labeled data structure with rows and columns, like a spreadsheet.
6. How do you read data from different file formats (CSV, Excel, JSON) in Python?
Using Pandas:
⦁ CSV:
pd.read_csv('file.csv')⦁ Excel:
pd.read_excel('file.xlsx')⦁ JSON:
pd.read_json('file.json')7. What is the difference between Python’s
append() and extend() methods?⦁
append() adds its argument as a single element to the end of a list.⦁
extend() iterates over its argument adding each element to the list.8. How do you filter rows in a Pandas DataFrame?
Using boolean indexing:
df[df['column'] > value] filters rows where ‘column’ is greater than value.9. Explain the use of
groupby() in Pandas with an example. groupby() splits data into groups based on column(s), then you can apply aggregation. Example:
df.groupby('category')['sales'].sum() gives total sales per category.10. What are lambda functions and how are they used?
Anonymous, inline functions defined with
lambda keyword. Used for quick, throwaway functions without formally defining with def. Example:
df['new'] = df['col'].apply(lambda x: x*2)
No comments:
Post a Comment