I.P File
I.P File
import pandas as pd
df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]})
df.rename(columns={'A': 'Alpha', 'B': 'Beta'}, inplace=True)
print(df)
Output:
Alpha Beta
0 1 4
1 2 5
2 3 6
---
import pandas as pd
series1 = pd.Series([1, 2, 3])
series2 = pd.Series([4, 5, 6])
result = series1 + series2
print(result)
Output:
0 5
1 7
2 9
dtype: int64
---
import pandas as pd
series = pd.Series([1, 2, 3])
result = series * 10
print(result)
Output:
0 10
1 20
2 30
dtype: int64
---
import pandas as pd
series = pd.Series([10, 20, 30, 40, 50])
slice_series = series[1:4]
print(slice_series)
Output:
1 20
2 30
3 40
dtype: int64
---
import pandas as pd
data = {'a': 10, 'b': 20, 'c': 30, 'd': 40}
series = pd.Series(data)
print(series)
Output:
a 10
b 20
c 30
d 40
dtype: int64
---
import numpy as np
arr_1d = np.array([1, 2, 3, 4])
arr_2d = np.array([[1, 2], [3, 4]])
print(arr_1d)
print(arr_2d)
Output:
[1 2 3 4]
[[1 2]
[3 4]]
---
import pandas as pd
series = pd.Series([20, 10, 30, 40])
sorted_series = series.sort_values()
print(sorted_series)
Output:
1 10
0 20
2 30
3 40
dtype: int64
---
import pandas as pd
series = pd.Series([10, 20, 30, 40, 50, 60])
print(series.head(3))
print(series.tail(2))
Output:
0 10
1 20
2 30
dtype: int64
4 50
5 60
dtype: int64
---
import pandas as pd
import numpy as np
series = pd.Series([1, 2, np.nan, 4, 5])
series_filled = series.fillna(0)
print(series_filled)
Output:
0 1.0
1 2.0
2 0.0
3 4.0
4 5.0
dtype: float64
---
import pandas as pd
df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]})
column_a = df['A']
print(column_a)
Output:
0 1
1 2
2 3
Name: A, dtype: int64
---
import pandas as pd
df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]})
row_column_selection = df.loc[0, 'A']
print(row_column_selection)
Output:
---
import pandas as pd
df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]})
filtered_df = df[df['A'] > 1]
print(filtered_df)
Output:
A B
1 2 5
2 3 6
---
import pandas as pd
df = pd.DataFrame({'A': [1, 2, 3]})
df['B'] = [4, 5, 6]
df['A'] = df['A'] * 10
print(df)
Output:
A B
0 10 4
1 20 5
2 30 6
---
Output:
A B
0 1 4
1 10 50
2 3 6
---
import pandas as pd
df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]})
df.drop('B', axis=1, inplace=True)
print(df)
Output:
A
0 1
1 2
2 3
---
import pandas as pd
df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]})
df.drop(1, axis=0, inplace=True)
print(df)
Output:
A B
0 1 4
2 3 6
---
17. Boolean Indexing in Series Objects
Output:
2 20
3 25
dtype: int64
---
Code:
import pandas as pd
Output:
B
0 4
1 5
2 6
---
Code:
import pandas as pd
Output:
1
20.Bar Chart
Program:
Output :
---
Program:
Output :
---
Program:
Output :
---
23.Histogram
Program:
Output :
---
24. Creating a CSV File
This Python script will create a CSV file named students.csv with sample student data.
import csv
Contents of students.csv:
StudentID,Name,Age,Class,Marks
1,John Doe,16,10,85
2,Jane Smith,17,11,90
3,Alice Brown,16,10,88
4,Tom Green,18,12,92
----
Next, we will read the contents of students.csv and display the rows.
import csv
-----
SQL QUERIES
SQL Command:
---
SQL Command:
---
SQL Command:
Output:
---
SQL Command:
Output:
---
SQL Command:
Output:
---
6. Update Records
SQL Command:
UPDATE Students
SET Marks = 92
WHERE StudentID = 2;
Updated Table:
---
7. Delete Records
SQL Command:
Updated Table:
---
8. Order Records
SQL Command:
Output:
---
SQL Command:
DESCRIBE Students;
Output:
---
SQL Command:
Output:
---
SQL Command:
Output:
---
SQL Command:
Output:
---
SQL Command:
---
SQL Command:
UPDATE Students
SET Class = '12'
WHERE StudentID = 1;
Updated Table:
---
SQL Command:
---
SQL Command:
---