-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path12 df 1.py
More file actions
59 lines (41 loc) · 1.59 KB
/
Copy path12 df 1.py
File metadata and controls
59 lines (41 loc) · 1.59 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import pandas as pd
import numpy as np
# as values : integers, float, string, list, tuple
mydict = {
'Name': ['Anastasia', 'Anastasia', 'Katherine', 'James', 'Emily', 'Michael', 'Matthew', 'Laura', 'Kevin', 'Jonas'],
'City': ['California', 'Los Angeles', 'California', 'California', 'California', 'Los Angeles', 'Los Angeles', 'Georgia', 'Georgia', 'Los Angeles'],
'Salary': [2000, 3000, 44000, 5000, 6000, 7000, 8000, 9000, 10000, 11000],
'Job Title':['Manager','Director','Sales Person','Manager','Director', np.nan,np.nan,np.nan,np.nan,np.nan],
'Age':[21,21,31,24,35,46,27,38,49,50]
}
print ( 'Length', len(mydict['Name']) )
print ( 'Length', len(mydict['City']) )
print ( 'Length', len(mydict['Salary']) )
print ( 'Length', len(mydict['Age']) )
print ( 'Length', len(mydict['Job Title']) )
##
dictKeys = mydict.keys()
print ('Keys', dictKeys)
##
for key, val in mydict.items():
print (key,"==>", val)
frame = pd.DataFrame(mydict)
print (frame)
##shape
print (frame.shape) #shape
#
print ('col', frame.columns)
print ( 'indexes', frame.index.values)
#
#value = 'The Wolf of Wallstreet'
#print ( value[0], value[4:8]) # with string, lists and tuples , simply slice
print(frame.loc[1:7,'Name':'Salary']) # slice by index and column names
print(frame.loc[1,'Name':'Salary'])
print(frame.loc[1:4,'Name'])
print(frame.loc[[1,7],'Name':'Salary'])
print(frame.loc[[1,7],['Name','Salary']])
# slice by position # Selecting Elements In A Series
print(frame.iloc[3])
print(frame.iloc[1:4,:])
print(frame.iloc[:,1:2])
print(frame.iloc[1,1])