Machine Learning
40.4K subscribers
3.62K photos
29 videos
47 files
647 links
Real Machine Learning โ€” simple, practical, and built on experience.
Learn step by step with clear explanations and working code.

Admin: @HusseinSheikho || @Hussein_Sheikho
Download Telegram
๐Ÿ’ก Pandas Cheatsheet

A quick guide to essential Pandas operations for data manipulation, focusing on creating, selecting, filtering, and grouping data in a DataFrame.

1. Creating a DataFrame
The primary data structure in Pandas is the DataFrame. It's often created from a dictionary.
import pandas as pd

data = {'Name': ['Alice', 'Bob', 'Charlie'],
'Age': [25, 32, 28],
'City': ['New York', 'Paris', 'New York']}
df = pd.DataFrame(data)

print(df)
# Name Age City
# 0 Alice 25 New York
# 1 Bob 32 Paris
# 2 Charlie 28 New York

โ€ข A dictionary is defined where keys become column names and values become the data in those columns. pd.DataFrame() converts it into a tabular structure.

2. Selecting Data with .loc and .iloc
Use .loc for label-based selection and .iloc for integer-position based selection.
# Select the first row by its integer position (0)
print(df.iloc[0])

# Select the row with index label 1 and only the 'Name' column
print(df.loc[1, 'Name'])

# Output for df.iloc[0]:
# Name Alice
# Age 25
# City New York
# Name: 0, dtype: object
#
# Output for df.loc[1, 'Name']:
# Bob

โ€ข .iloc[0] gets all data from the row at index position 0.
โ€ข .loc[1, 'Name'] gets the data at the intersection of index label 1 and column label 'Name'.

3. Filtering Data
Select subsets of data based on conditions.
# Select rows where Age is greater than 27
filtered_df = df[df['Age'] > 27]
print(filtered_df)
# Name Age City
# 1 Bob 32 Paris
# 2 Charlie 28 New York

โ€ข The expression df['Age'] > 27 creates a boolean Series (True/False).
โ€ข Using this Series as an index df[...] returns only the rows where the value was True.

4. Grouping and Aggregating
The "group by" operation involves splitting data into groups, applying a function, and combining the results.
# Group by 'City' and calculate the mean age for each city
city_ages = df.groupby('City')['Age'].mean()
print(city_ages)
# City
# New York 26.5
# Paris 32.0
# Name: Age, dtype: float64

โ€ข .groupby('City') splits the DataFrame into groups based on unique city values.
โ€ข ['Age'].mean() then calculates the mean of the 'Age' column for each of these groups.

#Python #Pandas #DataAnalysis #DataScience #Programming

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”
By: @DataScienceM โœจ
โค2๐Ÿ‘1
โ€ข Group data by a column.
df.groupby('col1')

โ€ข Group by a column and get the sum.
df.groupby('col1').sum()

โ€ข Apply multiple aggregation functions at once.
df.groupby('col1').agg(['mean', 'count'])

โ€ข Get the size of each group.
df.groupby('col1').size()

โ€ข Get the frequency counts of unique values in a Series.
df['col1'].value_counts()

โ€ข Create a pivot table.
pd.pivot_table(df, values='D', index=['A', 'B'], columns=['C'])


VI. Merging, Joining & Concatenating

โ€ข Merge two DataFrames (like a SQL join).
pd.merge(left_df, right_df, on='key_column')

โ€ข Concatenate (stack) DataFrames along an axis.
pd.concat([df1, df2]) # Stacks rows

โ€ข Join DataFrames on their indexes.
left_df.join(right_df, how='outer')


VII. Input & Output

โ€ข Write a DataFrame to a CSV file.
df.to_csv('output.csv', index=False)

โ€ข Write a DataFrame to an Excel file.
df.to_excel('output.xlsx', sheet_name='Sheet1')

โ€ข Read data from an Excel file.
pd.read_excel('input.xlsx', sheet_name='Sheet1')

โ€ข Read from a SQL database.
pd.read_sql_query('SELECT * FROM my_table', connection_object)


VIII. Time Series & Special Operations

โ€ข Use the string accessor (.str) for Series operations.
s.str.lower()
s.str.contains('pattern')

โ€ข Use the datetime accessor (.dt) for Series operations.
s.dt.year
s.dt.day_name()

โ€ข Create a rolling window calculation.
df['col1'].rolling(window=3).mean()

โ€ข Create a basic plot from a Series or DataFrame.
df['col1'].plot(kind='hist')


#Python #Pandas #DataAnalysis #DataScience #Programming

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”
By: @DataScienceM โœจ
โค6๐Ÿ‘1๐Ÿ”ฅ1
๐Ÿ“Œ How to Implement Randomization with the Python Random Module

๐Ÿ—‚ Category: PROGRAMMING

๐Ÿ•’ Date: 2025-11-24 | โฑ๏ธ Read time: 6 min read

Master Python's built-in random module to introduce unpredictability into your applications. This guide explores how to effectively generate random outputs, a crucial technique for tasks ranging from shuffling data and creating simulations to developing games and selecting random samples. Learn the core functions and practical implementations to leverage randomization in your code.

#Python #Programming #CodingTips #Random
โค3
๐Ÿ“Œ How to Generate QR Codes in Python

๐Ÿ—‚ Category: PROGRAMMING

๐Ÿ•’ Date: 2025-12-02 | โฑ๏ธ Read time: 7 min read

Unlock the ability to generate QR codes with Python. This beginner-friendly tutorial provides a step-by-step guide to using the popular "qrcode" package. Learn how to easily create and customize QR codes for your applications, from encoding URLs to embedding custom data.

#Python #QRCode #Programming #PythonTutorial
โค5
๐Ÿ‘ฃ Rust Interview Deep Dive ๐Ÿฆ€๐Ÿ”

A repository for systematic preparation for Rust interviews at the middle, senior, and staff levels. ๐Ÿ’ผ๐Ÿ“š

Inside 100 real questions from interviews in product and infrastructure companies, detailed analyses with code examples and scenarios of tasks that occur in production. ๐Ÿ’ป๐Ÿ—๏ธ Not "guess the program's output", but the mechanics on which real services are built. ๐Ÿ› ๏ธ๐Ÿš€

Here are lock-free structures, self-referential types in async, FFI with tensor libraries, correct Send on guards via await, memory ordering under loom, soundness of custom collections. ๐Ÿ”’โšก And it all starts with the basics. Ownership, borrowing, lifetimes. ๐Ÿงฑ๐Ÿ”„ Those who want can start from scratch or at the staff level. ๐Ÿšถโ€โ™‚๏ธ๐Ÿ‘จโ€๐Ÿ’ป

https://github.com/Develp10/rustinterviewquiestions ๐Ÿ”—

#Rust #Programming #InterviewPrep #SoftwareEngineering #SystemsProgramming #CareerGrowth
โค5
The math.perm() method

The math.perm() method in Python returns the number of ways to select k elements from n elements, with and without repetition. ๐Ÿงฎ

Syntax:
math.perm(n, k)

Where:
n: The number of elements from which k elements are selected.
k: The number of elements that are selected.

In the first example, the method returns the number of ways to select 3 elements from 5 elements. The result is 60 ways. ๐Ÿ“Š
In the second example, the method returns the number of ways to select 5 elements from 10 elements. The result is 252 ways. ๐Ÿš€

#Python #Math #Coding #Programming #DataScience #Tech

โœจ Join Best TG Channels https://xn--r1a.website/addlist/0f6vfFbEMdAwODBk

โญ๏ธ Join Our WhatsApp Channel https://whatsapp.com/channel/0029VaC7Weq29753hpcggW2A
โค10