try:
code
except(ValueError,ZeroDivisionError): #you can give multiple exception for same msg
print(’same msg for both errors’)
else:
print(’no exception’)
finally:
this clause always exsicuted
f=open("name","arw")
Print(f.realline)
Print(f.read)
Print(f.write)
for x in f:
print(x)
f.close()
PANDAS
Pandas gives you answers about the data. Like:
Is there a correlation between two or more columns?
What is average value?
Max value?
Min value?
Pandas are also able to delete rows that are not relevant, or contains wrong values, like empty or NULL v
alues. This is called cleaning the data.
It has functions for analyzing, cleaning, exploring, and manipulating data.
functions
import pandas as pd
1- pd.series
2- pd.DataFrame
3-pd.Loc[]
import pandas as pd
data = {
"calories": [420, 380, 390],
"duration": [50, 40, 45]
}
df = pd.DataFrame(data)
print(df.loc[0])
ANS=
calories 420
duration 50
4-df = pd.DataFrame(data, index = ["day1", "day2", "day3"])
import pandas as pd
data = {
"calories": [420, 380, 390],
"duration": [50, 40, 45]
}
df = pd.DataFrame(data, index = ["day1", "day2", "day3"])
print(df)
ANS=
calories duration
day1 420 50
day2 380 40
day3 390 45
3refferance with 4
print(df.loc["day2"])
ans=
calories 380
duration 40
5-pd.read_csv(’data.csv’)
6-pd.read_json(’data.json’)
import pandas as pd
df = pd.read_csv(’data.csv’)
df = pd.read_json(’data.json’)
print(df.to_string()) or print(df)
7-pd.options.display.max_rows
print(pd.options.display.max_rows)
8- df.head()
9- df.tail()
import pandas as pd
df = pd.read_csv(’data.csv’)
print(df.head(10))
10- df.info()
print(df.info())
_________________
try:
code
except(ValueError,ZeroDivisionError): #you can give multiple exception for same msg
print(’same msg for both errors’)
else:
print(’no exception’)
finally:
this clause always exsicuted
f=open("name","arw")
Print(f.realline)
Print(f.read)
Print(f.write)
for x in f:
print(x)
f.close()
PANDAS
Pandas gives you answers about the data. Like:
Is there a correlation between two or more columns?
What is average value?
Max value?
Min value?
Pandas are also able to delete rows that are not relevant, or contains wrong values, like empty or NULL v
alues. This is called cleaning the data.
It has functions for analyzing, cleaning, exploring, and manipulating data.
functions
import pandas as pd
1- pd.series
2- pd.DataFrame
3-pd.Loc[]
import pandas as pd
data = {
"calories": [420, 380, 390],
"duration": [50, 40, 45]
}
df = pd.DataFrame(data)
print(df.loc[0])
ANS=
calories 420
duration 50
4-df = pd.DataFrame(data, index = ["day1", "day2", "day3"])
import pandas as pd
data = {
"calories": [420, 380, 390],
"duration": [50, 40, 45]
}
df = pd.DataFrame(data, index = ["day1", "day2", "day3"])
print(df)
ANS=
calories duration
day1 420 50
day2 380 40
day3 390 45
3refferance with 4
print(df.loc["day2"])
ans=
calories 380
duration 40
5-pd.read_csv(’data.csv’)
import pandas as pd
print(df.to_string()) or print(df)
7-pd.options.display.max_rows
print(pd.options.display.max_rows)
8- df.head()
9- df.tail()
import pandas as pd
df = pd.read_csv(’data.csv’)
print(df.head(10))
10- df.info()
_________________