Path: blob/master/Data Science Essentials for Data Analysts/1.2 Python basics for Data Science.ipynb
3074 views
Python For Data Science
Python is one of the most popular languages used by Data Scientists. Python has in-built mathematical libraries and functions, making it easier to calculate mathematical functions.
Data Containers in Python
Strings 2. Lists 3. Tuples 4. Dictionary
Variable in Python
Operations on Numbers
Print Function
Type Conversion: Convert variable into another type e.g int to float
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Cell In[45], line 2
1 int(9.8)
----> 2 int("98a")
ValueError: invalid literal for int() with base 10: '98a'
Input
Quick Pratice:
Create python Script to input following details about your products:
Number of Products (30)
Name of Products Category (3*10)
Cost per Unit
Total Cost Price
Strings
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
Cell In[57], line 3
1 #Y[4]="E"
2 #del Y[0]
----> 3 del Y
4 Y
NameError: name 'Y' is not defined
Quick Practice:
Write a python script to open a railway ticket booking portal and enter following details from users :
1-Name
2-last Name
3-Age
4-Gender
5-Boarding Point
6-destination
String Functions and Methods
If else condition
Quick Parctice:
Write a python script to open a railway ticket booking portal and enter following details from users :
Ask for Sign in with UserName, Password (Greater than 5), Age > 16
Login for booking UserName and Pwd
1-Name 2-last Name 3-Age 4-Gender 5-Boarding Point 6-destination
Quick Pratice:
Create python Script to input following details about your products:
Number of Products (30)
Name of Products Category (3*10)
Cost per Unit
Total Cost Price
Quick Practice:
Please create a user name of length 6 if user name is valid then create a password of length 7, if pwd is valid then print("Welcome to homepage")
Write a program that performs addition, subtraction, multiplication, or division based on user input. Prompt the user to enter two numbers and an operation (+, -, *, /). Perform the calculation and print the result.
Bitwise operator
Work on binary representations of numbers.
Are useful for low-level programming, flags, or optimization tasks
Bitwise Operators in Python
Operator | Name | Description | Example (x=5, y=3) | Result |
---|---|---|---|---|
& | Bitwise AND | Performs AND operation on each bit. If both bits are 1, the result is 1, otherwise 0. | x & y | 1 |
` | ` | Bitwise OR | Performs OR operation on each bit. If either bit is 1, the result is 1. | `x |
^ | Bitwise XOR | Performs XOR operation on each bit. If the bits are different, the result is 1. | x ^ y | 6 |
~ | Bitwise NOT | Inverts all the bits of the number (1 becomes 0 and 0 becomes 1). | ~x | -6 |
<< | Left Shift | Shifts bits to the left by the specified number of positions. | x << 2 | 20 |
>> | Right Shift | Shifts bits to the right by the specified number of positions. | x >> 2 | 1 |
Notes:
Bitwise AND (
&
): Only 1 if both bits are 1.Bitwise OR (
|
): At least one bit must be 1.Bitwise XOR (
^
): True when bits differ.Bitwise NOT (
~
): Flips all bits; equivalent to-(x+1)
.Left Shift (
<<
): Shifts bits left, filling with zeros on the right.Right Shift (
>>
): Shifts bits right, discarding bits on the right.
Ques 2:
Input create a password with following critera:
Min len 3 and 10
Should contain one number
Should contain upper case member
Should not have a space
Shoukd have one special charactor sp=["@","?","*","$","&","^",#.!]
List
Dictionary
Mapping data types
Key value pairs
key are index to members for dictionary
Keys are unique with one value for one key
Duplicate Key creation is not possible
Loops
for i in range(1,6): range(6,2,-1) range(1,6):
Quick Practice 3 :
Create a list with all float values
Create a dictionary with Emp ID as Key and Names as Values