CBSE 2026
Important IP Programs
Master your practical exams with our curated list of essential Python and SQL programs for Class 12. Click on any question to view the code, copy it, or run it instantly.
Python 3
import pandas as pd
# Create empty Series
s = pd.Series()
print(s)
Python 3
import pandas as pd
data = [10, 20, 30, 40]
# Create Series
s = pd.Series(data)
print(s)
Python 3
import pandas as pd
import numpy as np
# Create numpy array
arr = np.array(['a', 'b', 'c', 'd'])
# Create Series
s = pd.Series(arr)
print(s)
Python 3
import pandas as pd
data = {'Jan': 31, 'Feb': 28, 'Mar': 31}
s = pd.Series(data)
print(s)
Python 3
import pandas as pd
# Index must be provided for scalar
s = pd.Series(100, index=[1, 2, 3, 4])
print(s)
Python 3
import pandas as pd
data = [10, 20, 30]
idx = ['A', 'B', 'C']
s = pd.Series(data, index=idx)
print(s)
Python 3
import pandas as pd
s = pd.Series([1, 2, 3])
s.name = "Numbers"
print(s)
Python 3
import pandas as pd
import numpy as np
s = pd.Series([1, 2, np.nan])
print("Has NaNs?", s.hasnans)
Python 3
import pandas as pd
s = pd.Series([10, 20, 30, 40])
print("Shape:", s.shape)
print("Size:", s.size)
Python 3
import pandas as pd
s = pd.Series([10, 20], index=['a', 'b'])
print("Values:", s.values)
print("Index:", s.index)
Python 3
import pandas as pd
s = pd.Series(range(1, 20)) # 1 to 19
print(s.head(3)) # First 3
Python 3
import pandas as pd
s = pd.Series(range(1, 20))
print(s.tail(3)) # Last 3
Python 3
import pandas as pd
s = pd.Series([10, 20, 30])
print(s + 5) # Adds 5 to all
Python 3
import pandas as pd
s = pd.Series([10, 20, 30])
print(s * 2)
Python 3
import pandas as pd
s = pd.Series([10, 50, 20, 90])
print(s > 40) # Returns Boolean Series
Python 3
import pandas as pd
s1 = pd.Series([1, 2, 3])
s2 = pd.Series([10, 20, 30])
print(s1 + s2)
Python 3
import pandas as pd
s1 = pd.Series([10], index=['a'])
s2 = pd.Series([20], index=['b'])
# Indices don't match, result is NaN
print(s1 + s2)
Python 3
import pandas as pd
s = pd.Series([10, 20, 30])
print("First element:", s[0])
Python 3
import pandas as pd
s = pd.Series([10, 20], index=['x', 'y'])
print("Element at 'y':", s['y'])
Python 3
import pandas as pd
s = pd.Series([10, 20, 30, 40, 50])
print(s[1:4]) # Indices 1, 2, 3
Python 3
import pandas as pd
s = pd.Series([1, 2, 3])
print(s[::-1])
Python 3
import pandas as pd
df = pd.DataFrame()
print(df)
Python 3
import pandas as pd
data = [ ['Amit', 90], ['Sumit', 85] ]
df = pd.DataFrame(data, columns=['Name', 'Marks'])
print(df)
Python 3
import pandas as pd
data = {
'Name': ['A', 'B', 'C'],
'Age': [17, 18, 17]
}
df = pd.DataFrame(data)
print(df)
Python 3
import pandas as pd
data = [
{'a': 10, 'b': 20},
{'a': 5, 'b': 10, 'c': 20}
]
df = pd.DataFrame(data)
print(df)
Python 3
import pandas as pd
s1 = pd.Series([1, 2], index=['a', 'b'])
s2 = pd.Series([3, 4], index=['a', 'b'])
data = {'One': s1, 'Two': s2}
df = pd.DataFrame(data)
print(df)
Python 3
import pandas as pd
df = pd.DataFrame({'A':[1], 'B':[2]})
print("Columns:", df.columns)
Python 3
import pandas as pd
df = pd.DataFrame({'A':[1], 'B':[2]}, index=['Row1'])
print("Index:", df.index)
Python 3
import pandas as pd
df = pd.DataFrame({'A':[1,2], 'B':[3,4]})
print("Shape:", df.shape) # Output (2, 2)
Python 3
import pandas as pd
df = pd.DataFrame({'A':[1,2], 'B':[3,4]})
print("Original:\n", df)
print("Transposed:\n", df.T)
Python 3
import pandas as pd
df = pd.DataFrame({'A':[1], 'B':[2]})
print(df.axes)
Python 3
import pandas as pd
df = pd.DataFrame({'A':[1], 'B':[2.5]})
print(df.dtypes)
Python 3
import pandas as pd
data = {'Name': ['A', 'B'], 'Age': [10, 12]}
df = pd.DataFrame(data)
print(df['Name'])
Python 3
import pandas as pd
data = {'Name': ['A', 'B'], 'Age': [10, 12], 'Class': [5, 6]}
df = pd.DataFrame(data)
print(df[['Name', 'Class']])
Python 3
import pandas as pd
df = pd.DataFrame({'Marks': [90, 80]}, index=['Ram', 'Shyam'])
print(df.loc['Ram'])
Python 3
import pandas as pd
df = pd.DataFrame({'Marks': [90, 80]}, index=['Ram', 'Shyam'])
print(df.iloc[0]) # First row
Python 3
import pandas as pd
df = pd.DataFrame({'Marks': [90]}, index=['Ram'])
print(df.loc['Ram', 'Marks'])
Python 3
import pandas as pd
df = pd.DataFrame({'A': [1,2,3,4]})
print(df[1:3]) # Rows at index 1 and 2
Python 3
import pandas as pd
data = {'Name': ['A', 'B', 'C'], 'Age': [18, 15, 20]}
df = pd.DataFrame(data)
# Show students older than 17
print(df[df['Age'] > 17])
Python 3
import pandas as pd
df = pd.DataFrame({'A': [1, 2]})
df['B'] = [3, 4] # Add column B
df['C'] = 10 # Add column C with scalar 10
print(df)
Python 3
import pandas as pd
df = pd.DataFrame({'A': [1], 'B': [2]})
del df['B']
print(df)
Python 3
import pandas as pd
df = pd.DataFrame({'A': [1], 'B': [2]})
val = df.pop('B')
print("Popped:", val)
print(df)
Python 3
import pandas as pd
df = pd.DataFrame({'A': [1, 2]}, index=['x', 'y'])
df2 = df.drop('x') # Removes row 'x'
print(df2)
Python 3
import pandas as pd
df = pd.DataFrame({'A': [1], 'B': [2]})
df2 = df.drop('B', axis=1)
print(df2)
Python 3
import pandas as pd
df = pd.DataFrame({'A': [1], 'B': [2]})
df = df.rename(columns={'A': 'Alpha', 'B': 'Beta'})
print(df)
Python 3
import pandas as pd
df = pd.DataFrame({'A': [1]}, index=['x'])
df = df.rename(index={'x': 'Row1'})
print(df)
Python 3
import pandas as pd
df = pd.DataFrame({'A': [10, 20]})
for index, row in df.iterrows():
print(index, row['A'])
Python 3
import pandas as pd
df = pd.DataFrame([[1, 2], [3, 4]])
print(df + 10)
Python 3
import pandas as pd
df = pd.DataFrame({'Name': ['A', 'B'], 'Marks': [90, 80]})
# index=False prevents writing row numbers
df.to_csv('students.csv', index=False)
print("File Saved")
Python 3
import pandas as pd
try:
df = pd.read_csv('students.csv')
print(df)
except FileNotFoundError:
print("Run program 49 first!")
Python 3
import pandas as pd
# If file has no header
df = pd.read_csv('students.csv', header=None)
print(df.head())
Python 3
import pandas as pd
df = pd.DataFrame({'A': [1], 'B': [2]})
df.to_csv('data.csv', sep='|')
print("Saved")
Python 3
import matplotlib.pyplot as plt
x = [1, 2, 3, 4]
y = [10, 20, 25, 30]
plt.plot(x, y)
plt.show()
Python 3
import matplotlib.pyplot as plt
x = [1, 2, 3]
y = [2, 4, 6]
plt.plot(x, y)
plt.title("Growth Chart")
plt.xlabel("Time")
plt.ylabel("Value")
plt.show()
Python 3
import matplotlib.pyplot as plt
plt.plot([1, 2, 3], [1, 4, 9], color='red', linestyle='dashed')
plt.show()
Python 3
import matplotlib.pyplot as plt
# 'o' is circle marker
plt.plot([1, 2, 3], [10, 20, 15], marker='o')
plt.show()
Python 3
import matplotlib.pyplot as plt
x = [1, 2, 3]
y1 = [10, 20, 30]
y2 = [15, 10, 5]
plt.plot(x, y1, label="Line A")
plt.plot(x, y2, label="Line B")
plt.legend() # Show legend
plt.show()
Python 3
import matplotlib.pyplot as plt
plt.plot([1, 2, 3], [10, 20, 30])
plt.grid(True)
plt.show()
Python 3
import matplotlib.pyplot as plt
plt.plot([1, 2], [1, 2])
plt.savefig("my_plot.png")
print("Plot saved")
Python 3
import matplotlib.pyplot as plt
classes = ['IX', 'X', 'XI', 'XII']
students = [40, 45, 30, 35]
plt.bar(classes, students)
plt.show()
Python 3
import matplotlib.pyplot as plt
y = ['A', 'B', 'C']
w = [10, 20, 15]
plt.barh(y, w)
plt.show()
Python 3
import matplotlib.pyplot as plt
x = ['A', 'B']
y = [10, 20]
plt.bar(x, y, color=['green', 'orange'])
plt.show()
Python 3
import matplotlib.pyplot as plt
plt.bar([1, 2], [10, 20], width=0.5)
plt.show()
Python 3
import matplotlib.pyplot as plt
ages = [10, 12, 12, 15, 15, 15, 20, 22]
plt.hist(ages, bins=3)
plt.show()
Python 3
import matplotlib.pyplot as plt
data = [1, 2, 2, 3, 3, 3, 4]
plt.hist(data, bins=4, edgecolor='black')
plt.show()
Python 3
import matplotlib.pyplot as plt
data = [5, 10, 15, 20, 25, 30]
plt.hist(data, bins=5, color='pink', edgecolor='red')
plt.show()
Python 3
import pandas as pd
df = pd.DataFrame({'A': [1]}, index=['r1'])
df.at['r1', 'A'] = 100
print(df)
Python 3
import pandas as pd
df = pd.DataFrame({'A': [3, 1, 2]})
sorted_df = df.sort_values(by='A')
print(sorted_df)
Python 3
import pandas as pd
import numpy as np
df = pd.DataFrame({'A': [1, np.nan, 2]})
print(df.fillna(0))
Python 3
import pandas as pd
import numpy as np
df = pd.DataFrame({'A': [1, np.nan, 2]})
print(df.dropna())