0% found this document useful (0 votes)
0 views4 pages

Python_for_Data_Science_Guide

The document provides an overview of fundamental Python programming concepts including variables, data types, lists, tuples, sets, dictionaries, conditional statements, loops, functions, importing libraries, file handling, and using Pandas and NumPy for data manipulation. It includes code examples for each concept, illustrating how to implement them in Python. Additionally, a mini project example demonstrates analyzing student grades using Pandas.

Uploaded by

naveedkhan34165
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views4 pages

Python_for_Data_Science_Guide

The document provides an overview of fundamental Python programming concepts including variables, data types, lists, tuples, sets, dictionaries, conditional statements, loops, functions, importing libraries, file handling, and using Pandas and NumPy for data manipulation. It includes code examples for each concept, illustrating how to implement them in Python. Additionally, a mini project example demonstrates analyzing student grades using Pandas.

Uploaded by

naveedkhan34165
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

1.

Variables and Data Types

Variables store data. Data types define the kind of data (string, number, boolean).

name = "Naveed"

age = 18

height = 5.9

is_student = True

2. Lists and Indexing

Lists store multiple values. Indexing starts at 0.

marks = [88, 92, 85, 79]

print(marks[0])

3. Tuples and Sets

Tuples are like lists but immutable. Sets are unordered and unique.

t = (1, 2, 3)

s = {1, 2, 2, 3}

print(s)

4. Dictionaries

Dictionaries store key-value pairs.

student = {"name": "Naveed", "age": 18, "marks": [88, 90, 85]}

print(student["marks"])

5. Conditional Statements

Used to make decisions.

score = 80

if score > 90:

print("Excellent")

elif score > 70:


print("Good")

else:

print("Try again")

6. Loops

Used to repeat actions. For and while loops are common.

for i in range(5):

print(i)

i = 0

while i < 3:

print(i)

i += 1

7. Functions

Functions are reusable blocks of code.

def greet(name):

print("Hello", name)

greet("Naveed")

8. Importing Libraries

Use libraries to extend Python's functionality.

import math

print(math.sqrt(16))

9. File Handling

Read/write from files using open().

with open("data.txt", "w") as file:


file.write("Test")

with open("data.txt", "r") as file:

print(file.read())

10. Pandas for CSV

Pandas is great for handling tabular data.

import pandas as pd

df = pd.read_csv("data.csv")

print(df.head())

11. NumPy for Arrays

NumPy is useful for numerical operations.

import numpy as np

a = np.array([1, 2, 3])

print(a * 2)

Mini Project Example

Analyze student grades using Pandas.

import pandas as pd

data = {

"Name": ["Ali", "Sara", "Naveed"],

"Math": [85, 90, 80],

"Science": [88, 95, 78]

df = pd.DataFrame(data)
df["Average"] = (df["Math"] + df["Science"]) / 2

print(df[df["Average"] > 85])

You might also like