Perfect channel to learn Data Analytics
Learn SQL, Python, Alteryx, Tableau, Power BI and many more
For Promotions: @coderfun @love_data
Post #2489
8.6K
- ❤ 7
DA @sqlspecialist
Showing posts older than #2490 · Back to latest
COUNT(*) counts all rows, including those with NULLs. COUNT(column_name) counts only rows where the column is NOT NULL. SELECT department, SUM(salary) FROM employees GROUP BY department;
SELECT COALESCE(phone, 'N/A') FROM users;
SELECT name,
CASE
WHEN score >= 90 THEN 'A'
WHEN score >= 75 THEN 'B'
ELSE 'C'
END AS grade
FROM students;
SELECT SUBSTRING('DataScience', 1, 4); -- Output: DataDATEDIFF(end_date, start_date) SELECT DATEDIFF('2026-01-10', '2026-01-05'); -- Output: 5SELECT ROUND(3.456, 2); -- Output: 3.46
import pandas as pd
df = pd.read_csv("sales_data.csv")
print(df.head())
print(df.shape)
df.info()
df.describe()
df.isnull().sum()
df.fillna(0) – Fill missing valuesdf.dropna() – Remove rows with nullsdf['Region'].value_counts()
df['Product'].unique()
df['Date'] = pd.to_datetime(df['Date'])
df['Amount'] = df['Amount'].astype(float)
df.duplicated().sum()
df.drop_duplicates(inplace=True)
import seaborn as sns
import matplotlib.pyplot as plt
sns.histplot(df['Sales'])
sns.boxplot(y=df['Profit'])
plt.show()
sns.scatterplot(x='Sales', y='Profit', data=df)
sns.boxplot(x='Region', y='Sales', data=df)
sns.heatmap(df.corr(numeric_only=True), annot=True)
df.groupby('Region')['Revenue'].sum()
df.groupby(['Region', 'Category'])['Sales'].mean()
df.set_index('Date')['Sales'].resample('M').sum().plot()
plt.title("Monthly Sales Trend")
name = "Alice" # String
age = 28 # Integer
height = 5.6 # Float
is_active = True # Boolean
fruits = ['apple', 'banana', 'mango']
print(fruits[0]) # apple
person = {'name': 'Alice', 'age': 28}
print(person['name']) # Alice score = 85
if score >= 90:
print("Excellent")
elif score >= 75:
print("Good")
else:
print("Needs improvement")
for fruit in fruits:
print(fruit)
count = 0
while count < 3:
print("Hello")
count += 1
def add(x, y):
return x + y
print(add(10, 5)) # 15
with open('data.txt', 'r') as file:
content = file.read()
print(content) import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
df = pd.read_csv('sales.csv') # Load data
print(df.head()) # Preview
# Basic stats
print(df.describe())
print(df['Revenue'].mean())
plt.plot(x, y) sns.barplot(x, y, data=df) from sklearn.preprocessing import MinMaxScaler
scaler = MinMaxScaler()
normalized_data = scaler.fit_transform(data)
df.loc[2] # Row with label 2
df.loc[:, 'age'] # All rows, 'age' column
df.iloc[2] # Third row
df.iloc[:, 1] # All rows, second column
merge() or concat()pd.merge(df1, df2, on='id', how='inner') # SQL-style joins
pd.concat([df1, df2], axis=0) # Stack rows
df.groupby('category')['sales'].sum()import numpy as np
a = np.array([1, 2, 3])
read_csv(..., chunksize=10000))SELECT column_name, COUNT(*)
FROM table_name
GROUP BY column_name
HAVING COUNT(*) > 1;