-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProg-5.py
More file actions
27 lines (21 loc) · 771 Bytes
/
Copy pathProg-5.py
File metadata and controls
27 lines (21 loc) · 771 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import pandas as pd
import numpy as np
# Sample dictionary data
exam_data = {
'name': ['Anastasia', 'Dima', 'Katherine', 'Suresh', 'Emily',
'Michael', 'Matthew', 'Laura', 'Kevin', 'Jonas'],
'score': [12.5, 9, 16.5, np.nan, 9, 20, 14.5, np.nan, 8, 19],
'attempts': [1, 3, 2, 3, 2, 3, 1, 1, 2, 1],
'qualify': ['yes', 'no', 'yes', 'no', 'no',
'yes', 'yes', 'no', 'no', 'yes']
}
# Index labels
labels = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
# Create DataFrame
df = pd.DataFrame(exam_data, index=labels)
print("Original DataFrame:\n")
print(df)
# Insert new column 'age'
df['age'] = [21, 23, 22, 20, 21, 24, 23, 22, 20, 25]
print("\nDataFrame after inserting new column:\n")
print(df)