import pandas as pd
person1 = {
"first": "Kushagra",
"last": "Gupta",
"email": "Kushagra225@gmail.com"
}
person2 = {
"first": ["Kushagra"],
"last": ["Gupta"],
"email": ["Kushagra225@gmail.com"]
}
person3 = {
"first": ["Kushagra", "Jane", "John"],
"last": ["Gupta", "Doe", "Doe"],
"email": ["Kushagra225@gmail.com", "JaneDoe123@gmail.com", "John@gmail.com"]
}
person3['email']
#converting dictionary to dataframe, dataframe is container of multiple series object..
df = pd.DataFrame(person3)
df
#access single column
df['email']
#series is list of data, rows of single column
type(df['email'])
# same as above,, but can be a problem when you have column name as same as method,, eg count
df.email
#access multiple column
df[['last', 'email']]
print(type(df[['last', 'email']]))
#gives all the columns name
df.columns
#gives number of rows & columns in df
df.shape
#gives number of rows & columns in df & their type
df.info()
#accessing 1st row of df
df.iloc[0]
#accessing particular row and column,, email of 1st and 2nd row data
df.iloc[[0,1], 2]
#we can write column name instead of number in loc
df.loc[[0,1], 'email']
df.loc[[0,1], ['email', 'first']]
#we can also use slicing in rows & columns and slicing in pandas is inclusive.. meaning 0:2 will return 0,1,2 index rows
df.loc[0:2, 'first':'email']