Related Coding Blogs

Practice Top 30 Python Programming Questions on Data Analysis, TechnoVlogs

Practice Top 30 Python Programming Questions on Data Analysis


Q1. Create a DataFrame with columns Name, Age, and City.
Input: {'Name': ['Alice', 'Bob'], 'Age': [25, 30], 'City': ['NY', 'LA']}
Expected Output:  
 
      Name  Age City
 0   Alice   25   NY
 1     Bob   30   LA

Q2. Read a CSV file data.csv and display the first 5 rows.
Input: CSV file with 10 rows and 3 columns.
Expected Output: First 5 rows of the DataFrame.

Q3. Filter rows where Age > 25.
Input: DataFrame:  
      Name  Age City
 0   Alice   25   NY
 1     Bob   30   LA

Expected Output:  
      Name  Age City
 1     Bob   30   LA

Q4. Sort the DataFrame by the Age column in descending order.
Input: Same as above.
Expected Output:  
      Name  Age City
 1     Bob   30   LA
 0   Alice   25   NY

Q5. Add a new column Salary with values [50000, 60000].
Input: Same DataFrame as above.
Expected Output:  
      Name  Age City  Salary
 0   Alice   25   NY   50000
 1     Bob   30   LA   60000

Q6. Drop the City column.
Input: Same DataFrame as above.
Expected Output:  
      Name  Age  Salary
 0   Alice   25   50000
 1     Bob   30   60000

Q7. Group by City and calculate the average Age.
Input:  
      Name  Age City
 0   Alice   25   NY
 1     Bob   30   LA
 2   Carol   35   NY
 
Expected Output:  
      City  Avg_Age
 0     LA       30
 1     NY       30

Q8. Create a pivot table showing the average Age for each City.
Input: Same as above.
Expected Output:  
      City
      LA     30
      NY     30

Q9. Fill missing values in Age with the mean.
Input: 
      Name   Age City
 0   Alice  25.0   NY
 1     Bob   NaN   LA
 2   Carol  35.0   NY
 
Expected Output: 
      Name   Age City
 0   Alice  25.0   NY
 1     Bob  30.0   LA
 2   Carol  35.0   NY

Q10. Save the DataFrame to a CSV file named output.csv.
Input: DataFrame as above.
Expected Output: A file output.csv.

Q11. Plot a line graph of x=[1, 2, 3] and y=[2, 4, 6].
Input: x and y arrays.
Expected Output: A line plot.

Q12. Plot a bar chart of Categories=['A', 'B', 'C'] and Values=[5, 7, 3].
Input: Lists.
Expected Output: A bar plot with three bars.

Q13. Create a scatter plot with x=[1, 2, 3] and y=[3, 5, 7].
Input: Lists.
Expected Output: A scatter plot.

Q14. Plot a histogram for the data [1, 2, 2, 3, 3, 3, 4].
Input: List.
Expected Output: A histogram with frequency counts.

Q15. Plot a heatmap for a DataFrame [[1, 2], [3, 4]].
Input: DataFrame.
Expected Output: A heatmap.

Q16. Add labels and a title to a line plot.
Input: x=[1, 2], y=[2, 4].
Expected Output: A line plot with title and labels.

Q17. Save a bar chart as chart.png.
Input: Bar chart.
Expected Output: chart.png saved.

Q18. Plot a pie chart for categories [A, B, C] with values [30, 50, 20].
Input: Lists.
Expected Output: A pie chart.

Q19. Create a pairplot for a DataFrame with sepal_length, sepal_width.
Input: DataFrame.
Expected Output: Pairplot visualizing relationships.

Q20. Create a boxplot for a DataFrame column.
Input: [1, 2, 3, 4, 5, 6].
Expected Output: A boxplot.

Q21. Create a 1D array [1, 2, 3, 4].
Input: [1, 2, 3, 4].
Expected Output: array([1, 2, 3, 4]).

Q22. Create a 2D matrix [[1, 2], [3, 4]].
Input: Matrix elements.
Expected Output:  
 array([[1, 2],
        [3, 4]])

Q23. Multiply each element of [1, 2, 3] by 2.
Input: [1, 2, 3].
Expected Output: [2, 4, 6].

Q24. Find the mean of [10, 20, 30].
Input: [10, 20, 30].
Expected Output: 20.0.

Q25. Compute the sum of elements in [1, 2, 3, 4].
Input: [1, 2, 3, 4].
Expected Output: 10.

Q26. Reshape [1, 2, 3, 4] into a 2x2 matrix.
Input: [1, 2, 3, 4].
Expected Output:  
 array([[1, 2],
        [3, 4]])

Q27. Generate 5 random numbers between 0 and 1.
Input: None.
Expected Output: Array of 5 random numbers.

Q28. Transpose the matrix [[1, 2], [3, 4]].

Expected Output:    
 array([[1, 3],
        [2, 4]])

Q29. Compute the dot product of [1, 2] and [3, 4].
Input: Two arrays.
Expected Output: 11.

Q30. Add [1, 2, 3] to [4, 5, 6].
Input: Two arrays.
Expected Output: [5, 7, 9].

Social Share

Bikki Singh Instructor TechnoVlogs

Bikki Singh

Hi, I am the instructor of TechnoVlogs. I have a strong love for programming and enjoy teaching through practical examples. I made this site to help people improve their coding skills by solving real-world problems. With years of experience, my goal is to make learning programming easy and fun for everyone. Let's learn and grow together!