User Tools

Site Tools


products:ict:python:pandas_questions

1. Q: What is Pandas?

 A: Pandas is an open-source data manipulation and analysis library for Python.

2. Q: How can you import the Pandas library in Python?

 A: You can import Pandas using the following statement: `import pandas as pd`.

3. Q: How do you read a CSV file into a Pandas DataFrame?

 A: You can use the `pd.read_csv()` function to read a CSV file into a DataFrame.

4. Q: How do you access the first few rows of a DataFrame?

 A: You can use the `.head()` method to access the first few rows of a DataFrame.

5. Q: How can you check the shape of a DataFrame (number of rows and columns)?

 A: You can use the `.shape` attribute of a DataFrame to check its shape.

6. Q: How do you select a single column from a DataFrame?

 A: You can use the indexing operator `[]` or the `.loc` or `.iloc` accessor to select a single column.

7. Q: How can you filter rows in a DataFrame based on a condition?

 A: You can use Boolean indexing by specifying a condition within square brackets `[]` to filter rows.

8. Q: How do you drop a column from a DataFrame?

 A: You can use the `.drop()` method with the `axis=1` argument to drop a column from a DataFrame.

9. Q: How do you rename a column in a DataFrame?

 A: You can use the `.rename()` method to rename one or more columns in a DataFrame.

10. Q: How can you handle missing values in a DataFrame?

  A: You can use the `.fillna()` method to replace missing values or the `.dropna()` method to remove rows with missing values.

11. Q: How do you sort a DataFrame by a specific column?

  A: You can use the `.sort_values()` method and specify the column to sort by.

12. Q: How can you group rows in a DataFrame based on a column?

  A: You can use the `.groupby()` method to group rows based on a column.

13. Q: How do you calculate the mean of a column in a DataFrame?

  A: You can use the `.mean()` method to calculate the mean of a column.

14. Q: How can you merge two DataFrames based on a common column?

  A: You can use the `.merge()` function and specify the common column to merge two DataFrames.

15. Q: How do you perform an inner join between two DataFrames?

  A: You can use the `.merge()` function with the `how='inner'` argument to perform an inner join.

16. Q: How can you pivot a DataFrame based on multiple columns?

  A: You can use the `.pivot()` function and specify multiple columns for the index, columns, and values.

17. Q: How do you apply a function to each element in a column?

  A: You can use the `.apply()` method and pass a function to apply it to each element in a column.

18. Q: How can you convert a DataFrame to a NumPy array?

  A: You can use the `.to_numpy()` method to convert a DataFrame to a NumPy array.

19. Q: How do you save a DataFrame to a CSV file?

  A: You can use the `.to_csv()` method and specify the file path to save a DataFrame to a CSV file.

20. Q: How can you plot a line graph using a column from a DataFrame?

  A: You can use the `.
  
  
products/ict/python/pandas_questions.txt · Last modified: 2023/05/06 16:39 by wikiadmin