Find top Python resources from global universities, cool projects, and learning materials for data analytics.
For promotions: @coderfun
Useful links: heylink.me/DataAnalytics
Post #1314
6.05K









๐ฐ Loops in Python
- โค 15
PY @pythonanalyst
Showing posts older than #1323 ยท Back to latest









.dropna(), .fillna() functions to do this easily.[x**2 for x in range(5)] โ ``pd.read_csv('file.csv')pd.read_excel('file.xlsx')pd.read_json('file.json')append() and extend() methods?append() adds its argument as a single element to the end of a list.extend() iterates over its argument adding each element to the list.df[df['column'] > value] filters rows where โcolumnโ is greater than value.groupby() in Pandas with an example. groupby() splits data into groups based on column(s), then you can apply aggregation. df.groupby('category')['sales'].sum() gives total sales per category.lambda keyword. Used for quick, throwaway functions without formally defining with def. df['new'] = df['col'].apply(lambda x: x*2)requests openpyxl, json, os, datetimescikit-learn read_csv, head(), info() plot(), bar(), hist() heatmap(), pairplot(), boxplot() openpyxl or xlsxwriter import numpy as np
arr = np.array([1, 2, 3])
print(arr * 2) # [2 4 6]
matrix = np.random.randint(1, 11, size=(3, 3))
print(matrix)
import pandas as pd
data = {"Name": ["Alice", "Bob"], "Age": [25, 30]}
df = pd.DataFrame(data)
print(df)
df = pd.read_csv("data.csv")
print(df.head())
import matplotlib.pyplot as plt
x = [1, 2, 3]
y = [2, 4, 1]
plt.plot(x, y)
plt.title("Simple Line Plot")
plt.show()
fruits = ["Apples", "Bananas", "Cherries"]
sales = [30, 45, 25]
plt.bar(fruits, sales)
plt.title("Fruit Sales")
plt.show()
import seaborn as sns
import matplotlib.pyplot as plt
tips = sns.load_dataset("tips")
sns.boxplot(x="day", y="total_bill", data=tips)
plt.show()
corr = tips.corr()
sns.heatmap(corr, annot=True, cmap="coolwarm")
plt.show()
import requests
response = requests.get("https://api.github.com")
print(response.status_code)
print(response.json())
res = requests.get("https://api.ipify.org?format=json")
print(res.json()["ip"])
from bs4 import BeautifulSoup
import requests
url = "https://example.com"
html = requests.get(url).text
soup = BeautifulSoup(html, "html.parser")
print(soup.title.text)
links = soup.find_all("a")
for link in links:
print(link.get("href"))