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

Numpy Cheatsheet ๐ฑ
- ๐ 3
- โค 1
PY @pythonanalyst
Showing posts older than #885 ยท Back to latest



import pandas as pd
df = pd.read_csv("data.csv")
df.to_excel("output.xlsx")
df.head()
df.info()
df.describe()
df[df["sales"] > 1000]
df[["name", "price"]]
df.fillna(0, inplace=True)
df.dropna(inplace=True)
import numpy as np
arr = np.array([1, 2, 3, 4])
print(arr.shape)
np.mean(arr)
np.median(arr)
np.std(arr)
import matplotlib.pyplot as plt
plt.plot([1, 2, 3, 4], [10, 20, 30, 40])
plt.bar(["A", "B", "C"], [5, 15, 25])
plt.show()
import seaborn as sns
sns.heatmap(df.corr(), annot=True)
sns.boxplot(x="category", y="sales", data=df)
plt.show()
df.isnull().sum()
df.corr()
sns.histplot(df["sales"], bins=30)
sns.boxplot(y=df["price"])
import sqlite3
conn = sqlite3.connect("database.db")
df = pd.read_sql("SELECT * FROM sales", conn)
conn.close()
cursor = conn.cursor()
cursor.execute("SELECT AVG(price) FROM products")
result = cursor.fetchone()
print(result)

Forwarded from Data Analytics

int, float, str, list, tuple, dict, and set to represent different forms of data.def keyword to perform specific tasks.for and while loops that allow you to repeat actions until a condition is met.if, elif, and else statements to execute code based on conditions.math, os, and datetime.try, except, finally blocks to manage and respond to runtime errors.
sales = {"January": 12000, "February": 15000, "March": 17000}
print(sales["February"]) # Output: 15000[ ].my_list = [10, 20, 30]
my_list.append(40)
( ).my_tuple = (10, 20, 30)
df.dropna()
df.fillna(0)
df.fillna(method='ffill') # Forward-fill
df.fillna(method='bfill') # Backfill
df_merged = pd.merge(df1, df2, on='common_column', how='inner')
df_concat = pd.concat([df1, df2], axis=1)
add = lambda x, y: x + y
print(add(10, 20)) # Output: 30
map() or filter().
import pandas as pd df = pd.read_csv('data.csv') print(df.head()) import numpy as np arr = np.array([10, 20, 30]) print(arr.mean()) # Calculates the average
import matplotlib.pyplot as plt plt.bar(['A', 'B', 'C'], [5, 7, 3]) plt.show()


