x = 11
x
y = 5.5
x + y
z = "string"
items = [1, 2, 5, 6]
items
# indexing
items[0]
for item in items:
print(item)
def square(x):
return x*x
square(2)
new = []
for item in items:
new.append(square(item))
new
import pandas as pd
data = {"area": ["north", "east", "west", "south", "central"],
"sales": [5, 25, 15, 20, 10],
"profit": [2, 8, 6, 5, 3]}
df = pd.DataFrame(data)
df
type(data), type(df)
# help
# ?pd.DataFrame
# Headers => columns
df.columns
# Row => Index
df.index
df["area"]
type(df.area)
df.head(2)
df.tail(2)
# Data back as a list
df.values
type(df.values)
First Way
df
df.iloc[0,0]
df.loc[0, "area"]
df.area[0]
Access this part of the dataframe
df
df.loc[2:3, ["area", "profit"]]
df.iloc[2:3, 0:1]
df.index = [5, 5, 8 , 3, 3]
df
df.loc[5:3, ["area", "profit"]]
df
df1 = df.copy()
df1.iloc[0,0] ="hello0000"
df1
df