Tech with hos
270 subscribers
162 photos
8 videos
1 file
53 links
Hosama | Tech With Hos
Daily simple tech insights โ€” programming, computer science basics, tools & modern tech trends.

No fluff. Just clear learning.
YouTube: https://youtube.com/@techwithhos?si=fGJhSe2Rv03aoeW0
Download Telegram
๐Ÿ“Š "Reading CSV Files with Python & Pandas!"
#TechWithHos #PythonTips #DataScience*

๐Ÿš€ *"Data is the new oil โ€” and Python is the drill."*

In this snippet, we explore how to read and extract data from a CSV file using both Pythonโ€™s built-in csv module and the powerful Pandas library.

import csv
'''
with open("/Users/kvava/OneDrive/Desktop/002 weather-data.csv") as data_s:
h = data_s.readlines()
print(h)

with open("/Users/kvava/OneDrive/Desktop/002 weather-data.csv") as data_s:
data = csv.reader(data_s)
tempratures = []

for row in data:
if row[1] != "temp":
temp = int(row[1])
tempratures.append(temp)
print(tempratures)
'''
import pandas

data = pandas.read_csv("/Users/kvava/OneDrive/Desktop/002 weather-data.csv")
print(data["temp"])


๐Ÿ” What this code does:

1. The first part (commented out) uses the csv module to manually read temperature values from a CSV file.
2. The second part uses Pandas to read the same file more efficiently โ€” and directly accesses the "temp" column.

๐Ÿ“Œ Why use Pandas?
Pandas is a powerful Python library for data manipulation and analysis. It makes working with structured data super easy โ€” whether itโ€™s filtering rows, summarizing columns, or transforming tables.

๐Ÿ”ฅ With Pandas, a few lines of code can replace dozens!
Perfect for data science, machine learning, or just wrangling messy spreadsheets.



๐Ÿ’ก Follow @TechWithHos for more Python & tech tips like this!
\#Python #Pandas #CodeSnippet #CSV #LearnToCode #ProgrammingTips
๐Ÿš€ Python List Comprehension โ€“ Clean, Powerful, and Pythonic! ๐Ÿ

List comprehensions make your code shorter, faster, and more readable. Whether you're transforming, filtering, or generating dataโ€”this tool is a must-know for any Pythonista!

Hereโ€™s a quick showcase of how elegant Python can be ๐Ÿ‘‡

# Add 1 to each item in a list
new_numbers = [item + 1 for item in numbers]

# Turn a string into a list of characters
name = "Angela"
new_list = [letter for letter in name]

# Square numbers from 1 to 4
new_double = [d * d for d in range(1, 5)]

# Double the numbers from 1 to 4
new_one = [s + s for s in range(1, 5)]

# Filter names with exactly 4 letters
names = ["Alex", "beth", "caroline", "Dave", "elias", "freddie"]
short_names = [sh for sh in names if len(sh) == 4]

# Capitalize names longer than 5 letters
capitalized = [ca.upper() for ca in names if len(ca) > 5]


โšก๏ธ Why use list comprehensions?
โœ… More readable than loops
โœ… Great for data transformations
โœ… Ideal for filtering and mapping
โœ… Just look cooler ๐Ÿ˜Ž

๐Ÿง  Try tweaking the conditions and expressionsโ€”it's one of the fastest ways to learn Python.

\#Python #ListComprehension #CodeSnippet #PythonTips