Notes DV
Notes DV
fibo(7)
0 1 1 2 3 5 8 13 21
Series :
A Pandas Series is like a column in a table.It is a one-dimensional array holding data of
any type.
0 1
1 2
2 3
3 4
4 5
dtype: int64
a Rajesh
b Suresh
c Ramesh
d Mahesh
dtype: object Rajesh
Porsche Panamera
Toyota MK5
Dodge Ram
dtype: object
DataFrames -
#Labeled Indexes
dfL=pd.DataFrame(data2,index=["s1","s2","s3"])
print("\n",dfL,"\n\n", dfL.loc["s1"])
Rajesh Rahul
0 eng sci
1 mat sst
2 hin eng
Rows of df :
Rajesh Rahul
0 eng sci
1 mat sst
Rajesh Rahul
s1 eng sci
s2 mat sst
s3 hin eng
Rajesh eng
Rahul sci
Name: s1, dtype: object
# row=[name,age,per]
# #to add new row in a dataframe
# df.loc[len(df)] = row
# print(df)
dict1={"name":["Raj","Rej","Rij","Roj"],"age":[18,14,16,15],"per":[97,94,74,86]}
df2=pd.DataFrame(dict1)
df=pd.concat([df,df2],ignore_index=True)
print(df)
print("Mean= ",df["age"].mean())
print("Mode= ",df["age"].mode())
print("Median", df["age"].median())
print("Standard Deviation= ",df["age"].std())
print("Variance= ",df["age"].var())
# Get the information about the data (Count, Mean, standard deviation, Min, Max,
print("\n****************** Describe ******************\n", df.describe())
# Creating a new coloumn name 'test' the values of this colomn sepal.len
df["test"] = df["sepal_length"] * df["sepal_width"]
df.to_csv("UpdatedCsv.csv")
# Group By show mean of the petal length and only print petal length coloumn
print("\n****************** Group By species & get petal length mean ***********
# Simple group by and get the uniqe species and only print sepal length coloumn
print("\n****************** Group By species & get varience of sepal length ***
sepal.area
50 22.40
51 20.48
52 21.39
54 18.20
55 15.96
.. ...
145 20.10
146 15.75
147 19.50
148 21.08
149 17.70
4 True
...
145 True
146 True
147 True
148 True
149 True
Name: sepal_width, Length: 150, dtype: bool
****************** Group By species & get the mean of sepal length **************
****
sepal_width petal_length petal_width sepal.area \
species sepal_length
setosa 4.3 3.000000 2.200000 0.100000 12.900000
4.4 3.033333 2.666667 0.200000 13.346667
4.5 2.300000 2.600000 0.300000 10.350000
4.6 3.325000 2.650000 0.225000 15.295000
4.7 3.200000 2.900000 0.200000 15.040000
4.8 3.180000 3.160000 0.200000 15.264000
4.9 3.075000 2.950000 0.125000 15.067500
5.0 3.362500 2.900000 0.287500 16.812500
5.1 3.600000 3.125000 0.312500 18.360000
5.2 3.666667 2.933333 0.166667 19.066667
5.3 3.700000 3.000000 0.200000 19.610000
5.4 3.660000 3.080000 0.320000 19.764000
5.5 3.850000 2.700000 0.200000 21.175000
5.7 4.100000 3.200000 0.350000 23.370000
5.8 4.000000 2.400000 0.200000 23.200000
versicolor 4.9 2.400000 6.600000 1.000000 11.760000
5.0 2.150000 6.800000 1.000000 10.750000
test Ratio
species sepal_length
setosa 4.3 12.900000 3.909091
4.4 13.346667 3.304029
4.5 10.350000 3.461538
4.6 15.295000 3.559524
4.7 15.040000 3.276442
4.8 15.264000 3.076692
4.9 15.067500 3.325000
5.0 16.812500 3.483001
5.1 18.360000 3.294678
5.2 19.066667 3.549206
5.3 19.610000 3.533333
5.4 19.764000 3.541357
5.5 21.175000 4.079670
5.7 23.370000 3.576471
5.8 23.200000 4.833333
versicolor 4.9 11.760000 1.484848
5.0 10.750000 1.471861
Height Weight
df = pd.DataFrame( columns=columns)
df.loc[0] = [1, 'M', 'Sunday', 12, 'Yes', 200, 18]
df.loc[1] = [2, 'F', 'Monday', 2, 'No', 300, 16]
df.loc[2] = [1, 'M', 'Sunday', 12, 'Yes', 150, 20]
df.loc[3] = [24, 'F', 'Monday', 21, 'No', 400, 11]
df.loc[4] = [2, 'F', 'Monday', 2, 'No', 250.12, 13]
df.loc[5] = [1, 'M', 'Sunday', 16, 'Yes', 320.1, 14]
df.loc[6] = [24, 'F', 'Monday', 6, 'No', 102.12, 15]
# Print the DataFrame
print(df)
plt.scatter(df["tip"],df["total_bill"],colour="green")
plt.scatter(df["qty"],df["tip"],colour="#88c999")
plt.show()
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[13], line 34
30 #plt.show()
31 plt.title("Total Bill vs Tip")
---> 34 plt.scatter(df["tip"],df["total_bill"],colour="green")
35 plt.scatter(df["qty"],df["tip"],colour="#88c999")
36 plt.show()
print(df)
rw = df.iloc[5]
print(rw)
plt.figure(figsize=(8,6))
plt.plot(df["total_bill"], df["tip"], marker="^", color="green", linestyle='-')
plt.xlabel("Total Bill")
plt.ylabel("Tip")
plt.title("Change in tip w.r.t. total bill")
colors=["red","yellow","green","blue","orange","black"]
sizes=[10,20,30,40,50,60]
plt.scatter(df["tip"], df["total_bill"], c=colors, s=sizes, alpha=0.7)
plt.scatter(df["qty"],df["tip"],color="#aa1199")
for(i,j) in zip(df["qty"],df["tip"]):
plt.text(i,j, f"({i},{j})")
plt.show()
colors=["green","blue"]
plt.hist(student_df[["english_marks", "maths_marks"]],bins=4,color=colors,alpha=
plt.legend (fontsize=10)
plt.show()
share= [15,20,25,40,55]
fig, ex=plt.subplots()
#ex.pie(share,autopct="%1.1f%%",labels=l,colors=["red","orange","gray","brown","
ex.pie(share,radius=0.5,autopct="%1.1f%%",labels=l,colors=["red","orange","gray"
plt.show()