-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSample python dictionary
More file actions
37 lines (27 loc) · 1.14 KB
/
Sample python dictionary
File metadata and controls
37 lines (27 loc) · 1.14 KB
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
28
29
30
31
32
33
34
35
36
37
import pandas as pd
import numpy as np
# Sample Python dictionary data and list labels
exam_data = {'name': ['Anastasia', 'Dima', 'Katherine', 'James', '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, 1, 1, 2, 1, 1, 2],
'qualify': ['yes', 'no', 'yes', 'no', 'no', 'yes', 'yes', 'no', 'yes', 'yes']}
labels = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
# Create the DataFrame with the specified data and index labels
df = pd.DataFrame(exam_data, index=labels)
# Display the DataFrame
print("DataFrame created from the dictionary:")
print(df)
# Change the name 'James' to 'Suresh' in the 'name' column
df.loc['d', 'name'] = 'Suresh'
# Display the updated DataFrame
print(df)
# Create a list of salaries
salaries = [50000, 60000, 75000, 45000, 55000, 80000, 70000, 48000, 62000, 78000]
# Insert the new column 'salary'
df['salary'] = salaries
# Display the DataFrame with the new column
print(df)
# Get the list of column headers
column_headers = df.columns.tolist()
# Display the list of headers
print(column_headers)