In [2]:
 #Example: Assigning values to variables
name = "John"
age = 25
print(age) #The print() function is used to display output on the console.
25
In [3]:
# Example: Arithmetic operations
x = 10
y = 5
# Addition
sum_result = x + y
print(sum_result)
#Subtraction
difference_result = x - y
print(difference_result)
#Multiplication
product_result = x * y
print(product_result)
#Division
division_result = x / y
print(division_result)
#Exponential
exponentiation_result = x ** y
print(exponentiation_result)
15
5
50
2.0
100000
In [4]:
# Creating a list of numbers
numbers = [1, 2, 3, 4, 5]
# Accessing elements in the list
print(numbers[0]) # Output: 1
print(numbers[2]) # Output: 3
1
3
In [5]:
# Adding elements to the list
numbers.append(6)
print(numbers) # Removing elements from the list
numbers.remove(4)
print(numbers) # Output: [1, 2, 3, 4, 5, 6]
# Output: [1, 2, 3, 5, 6]
[1, 2, 3, 4, 5, 6]
[1, 2, 3, 5, 6]
In [6]:
# Creating a tuple of coordinates
point = (10, 20)
# Accessing elements in the tuple
print(point[0]) # Output: 10
print(point[1]) # Output: 20
# Tuples are immutable - you cannot change the elements
# Uncommenting the line below will raise an error
# point[0] = 5
10
20
In [7]:
# Creating a dictionary of student details
student = {
'name': 'Alice',
'age': 20,
'grade': 'A'
}
# Accessing elements in the dictionary using keys
print(student['name']) # Output: Alice
print(student['age']) # Output: 20
# Adding elements to the dictionary
student['city'] = 'New York'
print(student) # Output: {'name': 'Alice', 'age': 20, 'grade': 'A', 'city': 'New Yor
# Removing elements from the dictionary
del student['grade']
print(student) # Output: {'name': 'Alice', 'age': 20, 'city': 'New York'}
Alice
20
{'name': 'Alice', 'age': 20, 'grade': 'A', 'city': 'New York'}
{'name': 'Alice', 'age': 20, 'city': 'New York'}
In [8]:
# Creating a set of unique colors
colors = {'red', 'green', 'blue'}
# Adding elements to the set
colors.add('yellow')
print(colors) # Output: {'blue', 'green', 'yellow', 'red'}
# Sets do not allow duplicates
colors.add('red')
print(colors) # Output: {'blue', 'green', 'yellow', 'red'}
{'yellow', 'green', 'blue', 'red'}
{'yellow', 'green', 'blue', 'red'}
In [10]:
# Example of if statement
age = 18
if age >= 18:
  print("You are an adult.")
else:
  print("You are a minor.")
You are an adult.
In [12]:
# Example of for loop
numbers = [1, 2, 3, 4, 5]
for num in numbers:
  print(num)
1
2
3
4
5
In [13]:
# Example of while loop
count = 0
while count < 5:
  print("Count:", count)
  count += 1
Count: 0
Count: 1
Count: 2
Count: 3
Count: 4
In [15]:
 # Example of logical operators
x = 10
y = 5
if ((x > 5) & (y < 8)):
  print("Both conditions are met.")

if ((x > 12) | (y < 3)):
  print("At least one condition is met.")

if not x < 5:
  print("The condition is False, but 'not' makes it True.")
Both conditions are met.
The condition is False, but 'not' makes it True.
In [16]:
import pandas as pd
# Specify the file path
file_path = '/content/sample_data/california_housing_test.csv' # Replace 'data.csv' with the
# Read the CSV file into a DataFrame
df = pd.read_csv(file_path)
# Print the DataFrame
print(df)
      longitude  latitude  housing_median_age  total_rooms  total_bedrooms  \
0       -122.05     37.37                27.0       3885.0           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   
...         ...       ...                 ...          ...             ...   
2995    -119.86     34.42                23.0       1450.0           642.0   
2996    -118.14     34.06                27.0       5257.0          1082.0   
2997    -119.70     36.30                10.0        956.0           201.0   
2998    -117.12     34.10                40.0         96.0            14.0   
2999    -119.63     34.42                42.0       1765.0           263.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  
...          ...         ...            ...                 ...  
2995      1258.0       607.0         1.1790            225000.0  
2996      3496.0      1036.0         3.3906            237200.0  
2997       693.0       220.0         2.2895             62000.0  
2998        46.0        14.0         3.2708            162500.0  
2999       753.0       260.0         8.5608            500001.0  

[3000 rows x 9 columns]
In [ ]:
 
In [ ]:
!jupyter nbconvert --to html bana320_lecture1.ipynb
[NbConvertApp] Converting notebook bana310_final.ipynb to html
[NbConvertApp] WARNING | Alternative text is missing on 14 image(s).
[NbConvertApp] Writing 963726 bytes to bana310_final.html