0
0
Pandasdata~15 mins

Creating DataFrame from NumPy array in Pandas - Try It Yourself

Choose your learning style9 modes available
Creating DataFrame from NumPy array
📖 Scenario: You work in a small shop and have sales data stored as numbers in a NumPy array. You want to organize this data into a table with labels for each column to understand it better.
🎯 Goal: Create a pandas DataFrame from a given NumPy array and add column names to make the data easy to read.
📋 What You'll Learn
Create a NumPy array named sales_data with the exact values [[10, 20, 30], [15, 25, 35], [20, 30, 40]]
Create a list named columns with the exact values ['Monday', 'Tuesday', 'Wednesday']
Create a pandas DataFrame named df from sales_data with columns set to columns
Print the DataFrame df to display the table
💡 Why This Matters
🌍 Real World
Organizing raw numerical data into tables helps businesses analyze sales, inventory, or customer information clearly.
💼 Career
Data scientists and analysts often convert arrays or raw data into DataFrames to prepare for analysis and visualization.
Progress0 / 4 steps
1
Create the NumPy array with sales data
Import NumPy as np and create a NumPy array called sales_data with these exact values: [[10, 20, 30], [15, 25, 35], [20, 30, 40]]
Pandas
Need a hint?

Use np.array() to create the array with the exact nested list of numbers.

2
Create the list of column names
Create a list called columns with these exact strings: 'Monday', 'Tuesday', and 'Wednesday'
Pandas
Need a hint?

Use square brackets [] to create the list with the exact day names as strings.

3
Create the pandas DataFrame from the NumPy array
Import pandas as pd and create a DataFrame called df from sales_data using columns=columns to set the column names
Pandas
Need a hint?

Use pd.DataFrame() with the columns parameter to add column names.

4
Print the DataFrame to see the table
Write a print statement to display the DataFrame df
Pandas
Need a hint?

Use print(df) to show the table in the output.