Start coding or generate with AI.
#import the pandas library as pd short
import pandas as pd
#file path
file_path = '/content/sample_data/california_housing_test.csv'
#read the file to Dataframe
Dframe = pd.read_csv(file_path)
#Display rows from Dataframe
[ ]
print(Dframe.head())
output 0
longitude
-122.05
latitude
37.37
housing_median_age
27.0
total_rooms
3885.0
total_bedrooms
661.0
\
1 -118.30 34.26 43.0 1510.0 310.0
2 -117.81 33.78 27.0 3589.0 507.0
3 -118.36 33.82 28.0 67.0 15.0
4 -119.67 36.33 19.0 1241.0 244.0
population households median_income median_house_value
0 1537.0 606.0 6.6085 344700.0
1 809.0 277.0 3.5990 176500.0
2 1484.0 495.0 5.7934 270500.0
3 49.0 11.0 6.1359 330000.0
4 850.0 237.0 2.9375 81700.0
Double-click (or enter) to edit
#import pandas library
import pandas as pd
# Dictionary created with data for data frame
data = {'col1': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 'col2': ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']}
#DataFrame function read the data (input) from dictionary into Dtaframe(object) df1
df1 = pd.DataFrame(data)
#select first 5 rows of the original dataframe and stores in new dataframe df2
df2 = df1.head(5)
print(df2)
col1 col2
0 1 a
1 2 b
2 3 c
3 4 d
4 5 e
Double-click (or enter) to edit
Double-click (or enter) to edit
#import the essential plotting library
import matplotlib.pyplot as plt
#create a dictionary data to store the data
data = {
"Date": ["2023-01-01", "2023-02-01", "2023-03-01", "2023-04-01", "2023-05-01", "2023-06-01"],
"Sales": [100, 120, 150, 180, 200, 220]
}
# Extract the column to visualize
#assigns the name of the column you want to vizualize
column_name = "Sales"
#extraxt the data of the specified column into a seperate variable
coulmn_data = data[column_name]
# Create the line plot using the data provided
plt.plot(column_data)
# Customize the plot
#set the lable as Date for x axis
plt.xlabel("Date")
#set the label as "coulmn_name" for y axis which is sales
plt.ylabel("Sales")
#Add plot title
plt.title("Trend of" + column_name)
#Add grid enabling readability and visual guidance
plt.grid(True)
# Show the plot
plt.show()
#import Data Visualization library
import seaborn as sns
#import pandas library If data is in a DataFrame
import pandas as pd
# Data
data = pd.DataFrame({
"column_name": [10, 20, 30, 40, 50, 25, 15, 35,45] })
# Choose the numerical column to visualize
column_to_visualize = "column_name"
# Create the histogram with Seaborn
sns.histplot(data=data, x=column_to_visualize)
# Show the plot
#plt.show()
<Axes: xlabel='column_name', ylabel='Count'>
#import the numpy library
import numpy as np
# Create an empty NumPy array of size 5
array = np.zeros(5)
# Get input values from the user for arr[0 -4]
for i in range(5):
value = float(input(f"Enter value{i+1}:"))
array[i] = value
# Calculate the mean of the array
mean = np.mean(array)
# Display the array and its mean
print("Array:",array)
print("Mean:",mean)
Enter value1:1
Enter value2:2
Enter value3:3
Enter value4:4
Enter value5:5
Array: [1. 2. 3. 4. 5.]
Mean: 3.0