Tuesday, October 5, 2021

DataFrame in Python - 5

1. 

Add New Row in DataFrame 

import pandas as pd

D={'Name':['ritu','ajay','pankaj','aditya'],'English':[67,78,75,88],'Bio':[78,67,89,90],'Physics':[34,45,67,78],'Chem':[23,32,67,87]}

df=pd.DataFrame(D)

print(df)

#Add New Row in DataFrame

df.loc['4']={'Name':'udai','English':55 ,'Bio':98,'Physics':89 ,'Chem':56}

print(df)


Output:


========== RESTART: C:\Users\acer\AppData\Local\Programs\Python\Python39\DF4.py ==========
     Name  English  Bio  Physics  Chem
0    ritu       67   78       34    23
1    ajay       78   67       45    32
2  pankaj       75   89       67    67
3  aditya       88   90       78    87
     Name  English  Bio  Physics  Chem
0    ritu       67   78       34    23
1    ajay       78   67       45    32
2  pankaj       75   89       67    67
3  aditya       88   90       78    87
4    udai       55   98       89    56



2. 
Modify the row in DataFrame


import pandas as pd
D={'Name':['ritu','ajay','pankaj','aditya'],'English':[67,78,75,88],'Bio':[78,67,89,90],'Physics':[34,45,67,78],'Chem':[23,32,67,87]}
df=pd.DataFrame(D)
print(df)
#modify the row
df.loc[1]=["ajay",61,62,63,64]
print(df)


Output:



 ==========
     Name  English  Bio  Physics  Chem
0    ritu       67   78       34    23
1    ajay       78   67       45    32
2  pankaj       75   89       67    67
3  aditya       88   90       78    87
     Name  English  Bio  Physics  Chem
0    ritu       67   78       34    23
1    ajay       61   62       63    64
2  pankaj       75   89       67    67
3  aditya       88   90       78    87
>>> 



3.
Rename the column in DataFrame

import pandas as pd
D=[10,20,30,40,50]
df=pd.DataFrame(D)
print(df)
df.columns=["Roll No."]
print(df)



Output:

    0
0  10
1  20
2  30
3  40
4  50
   Roll No.
0        10
1        20
2        30
3        40
4        50


4. 
Rename Multiple columns in DataFrame


import pandas as pd
D={"Name":["Ram","Raj","Sam","John","Amit"],"Roll No.":[10,20,30,40,50]}
df=pd.DataFrame(D)
print(df)
df.columns=["Std_Name","Std_id"]
print(df)

Output:


   Name  Roll No.
0   Ram        10
1   Raj        20
2   Sam        30
3  John        40
4  Amit        50
  Std_Name  Std_id
0      Ram      10
1      Raj      20
2      Sam      30
3     John      40
4     Amit      50





import pandas as pd
D={"Name":["Raju","Raj","Ram"],"IP":[30,32,28],"Bio":[25,28,32]}
df=pd.DataFrame(D)
print(df)
df.rename(columns={"Bio":"Biology","IP":"Informatics Practices"},inplace=True)
print(df)



   Name  IP  Bio
0  Raju  30   25
1   Raj  32   28
2   Ram  28   32
   Name  Informatics Practices  Biology
0  Raju                     30       25
1   Raj                     32       28
2   Ram                     28       32


Monday, October 4, 2021

WAP in Python to create a calculator

#WAP in Python to create a calculator

a=int(input("Enter First Number: "))

b=int(input("Enter Second Number: "))

sum=a+b

sub=a-b

pro=a*b

div=a/b

fdiv=a//b

exp=a**b

rem=a%b

print("Sum=",sum)

print("Difference=",sub)

print("Product=",pro)

print("Division=",div)

print("Floor Division=",fdiv)

print("Exponational=",exp)

print("Modulus=",rem)


Output



Enter First Number: 22
Enter Second Number: 5
Sum= 27
Difference= 17
Product= 110
Division= 4.4
Floor Division= 4
Exponational= 5153632
Modulus= 2


2.
#WAP in Python to calculate simple interest
P=float(input("Enter the principal amount: "))
R=float(input("Enter rate of interest Yearly: "))
T=int(input("Enter the number of year: "))
SI=P*R*T/100
print("Simple Interest=",SI)


Output:

Enter the principal amount: 5000
Enter rate of interest Yearly: 24
Enter the number of year: 5
Simple Interest= 6000.0

Thursday, September 30, 2021

DataFrame in Python Class - 4

1

 #Sort the values of DataFrame

import pandas as pd

I=['IP','Bio','Chemistry','Physics','English']

D={"2018":[50,60,70,80.5,90],"2019":[40,35,45,55,32], \

   "2020":[65,75,85,45,52],}

df=pd.DataFrame(D,I)

print(df)

print(df.sort_values(by=["2019"]))

    

print(df.sort_values(by=["2019"],ascending=True))

print(df.sort_values(by=["2019"],ascending=False))




Output:


           2018  2019  2020
IP         50.0    40    65
Bio        60.0    35    75
Chemistry  70.0    45    85
Physics    80.5    55    45
English    90.0    32    52
           2018  2019  2020
English    90.0    32    52
Bio        60.0    35    75
IP         50.0    40    65
Chemistry  70.0    45    85
Physics    80.5    55    45
           2018  2019  2020
English    90.0    32    52
Bio        60.0    35    75
IP         50.0    40    65
Chemistry  70.0    45    85
Physics    80.5    55    45
           2018  2019  2020
Physics    80.5    55    45
Chemistry  70.0    45    85
IP         50.0    40    65
Bio        60.0    35    75
English    90.0    32    52



2.
#Create a DataFrame using Dictionary and default index
import pandas as pd

D={"Name":["Ram","Raj","Sam","John"],"CS":[50,75,55,82], \
   "Maths":[40,35,45,55], \
   "IP":[65,75,85,45]}
df=pd.DataFrame(D)
print(df)



   Name  CS  Maths  IP
0   Ram  50     40  65
1   Raj  75     35  75
2   Sam  55     45  85
3  John  82     55  45



3.
#Create a DataFrame using Dictionary of Series
import pandas as pd
n=pd.Series(["Ram","Raj","Sam","John"])
cs=pd.Series([50,75,55,82])
maths=pd.Series([40,35,45,55])
ip=pd.Series([65,75,85,45])
data={"Name":n,"CS":cs,"Maths":maths,"IP":ip}
df=pd.DataFrame(data)
print(df)


Output:

  Name  CS  Maths  IP
0   Ram  50     40  65
1   Raj  75     35  75
2   Sam  55     45  85
3  John  82     55  45



4.
#Create a DataFrame using Dictionary of Series by directly passing the values to the dictionary  
import pandas as pd
data={"Name":pd.Series(["Ram","Raj","Sam","John"]),
      "CS":pd.Series([50,75,55,82]),
      "Maths":pd.Series([40,35,45,55]),
      "IP":pd.Series([65,75,85,45])}
df=pd.DataFrame(data)
print(df)

Output:

   Name  CS  Maths  IP
0   Ram  50     40  65
1   Raj  75     35  75
2   Sam  55     45  85
3  John  82     55  45



5.
#Create a DataFrame by passing a list of dictionaries
import pandas as pd
data=[{"Ram":45,"Raj":43,"Sam":27,"John":50},
      {"Ram":40,"Raj":35,"Sam":45,"John":30},
      {"Ram":65,"Raj":75,"Sam":60,"John":55}]
df=pd.DataFrame(data)
print(df)

Output:

   Ram  Raj  Sam  John
0   45   43   27    50
1   40   35   45    30
2   65   75   60    55



6.
#Create a DataFrame from numpy ndarray
import pandas as pd
import numpy as np
array=np.array([[67,77,75,78],
        [67,78,75,88],
        [78,67,89,90],
        [78,88,98,90]])
column_values=['English','Economics','IP','Accounts']
df=pd.DataFrame(array,columns=column_values)
print(df)

Output:

   English  Economics  IP  Accounts
0       67         77  75        78
1       67         78  75        88
2       78         67  89        90
3       78         88  98        90



7.
#To display records from the first to the third row
import pandas as pd
D={'Name':['ritu','ajay','pankaj','aditya'],'English':[67,78,75,88],'Bio':[78,67,89,90],'Physics':[34,45,67,78],'Chem':[23,32,67,87]}
df=pd.DataFrame(D)
print(df)
print(df[1:3])

Output:
     Name  English  Bio  Physics  Chem
0    ritu       67   78       34    23
1    ajay       78   67       45    32
2  pankaj       75   89       67    67
3  aditya       88   90       78    87
     Name  English  Bio  Physics  Chem
1    ajay       78   67       45    32
2  pankaj       75   89       67    67




8.
#To create an indexed DataFrame using list
import pandas as pd
D={'Name':['ritu','ajay','pankaj','aditya'],'English':[67,78,75,88],'Bio':[78,67,89,90],'Physics':[34,45,67,78],'Chem':[23,32,67,87]}
df=pd.DataFrame(D, index=['S1','S2','S3','S4'])
print(df)
print(df[1:3])


Output:

      Name  English  Bio  Physics  Chem
S1    ritu       67   78       34    23
S2    ajay       78   67       45    32
S3  pankaj       75   89       67    67
S4  aditya       88   90       78    87
   




9.
#To change the index column (set the DataFrame Column as Index) of DataFrame
import pandas as pd
D={'Name':['ritu','ajay','pankaj','aditya'],'English':[67,78,75,88],'Bio':[78,67,89,90],'Physics':[34,45,67,78],'Chem':[23,32,67,87]}
df=pd.DataFrame(D)
print(df)
df.set_index('Name',inplace=True)
print("New DataFrame:")
print(df)


Output:

 ==========
     Name  English  Bio  Physics  Chem
0    ritu       67   78       34    23
1    ajay       78   67       45    32
2  pankaj       75   89       67    67
3  aditya       88   90       78    87
New DataFrame:

        English  Bio  Physics  Chem
Name                               
ritu         67   78       34    23
ajay         78   67       45    32
pankaj       75   89       67    67
aditya       88   90       78    87



10. 
Reset the Index column of a DataFrame i.e. Reset to the original DataFrame

import pandas as pd
D={'Name':['ritu','ajay','pankaj','aditya'],'English':[67,78,75,88],'Bio':[78,67,89,90],'Physics':[34,45,67,78],'Chem':[23,32,67,87]}
df=pd.DataFrame(D)
print(df)
df.set_index('Name',inplace=True)
print("New DataFrame:")
print(df)
df.reset_index(inplace=True)
print("Original DataFrame:")
print(df)



Output:


    Name  English  Bio  Physics  Chem
0    ritu       67   78       34    23
1    ajay       78   67       45    32
2  pankaj       75   89       67    67
3  aditya       88   90       78    87
New DataFrame:
        English  Bio  Physics  Chem
Name                               
ritu         67   78       34    23
ajay         78   67       45    32
pankaj       75   89       67    67
aditya       88   90       78    87
Original DataFrame:
     Name  English  Bio  Physics  Chem
0    ritu       67   78       34    23
1    ajay       78   67       45    32
2  pankaj       75   89       67    67
3  aditya       88   90       78    87





Wednesday, September 29, 2021

Date Sheet of Pre-Board 2021

 

Computer Science and IP Pre-Board Exam Date is 21 Oct 2021 Timing 04:00 PM - 05:30 PM

DataFrame in Python Class - 3

 

1.

#Create an Empty DataFrame

import pandas as pd

df=pd.DataFrame()

print(df)


Output:

Empty DataFrame
Columns: []
Index: []


2.

#Create a DataFrame using list
import pandas as pd
D=[10,15,20,25,35]
df=pd.DataFrame(D)
print(df)

Output:

    0
0  10
1  15
2  20
3  25
4  35


3.

#Create a DataFrame using list of multiple columns
import pandas as pd
D=[["Udai",17],["Aditya",15],["Aakash",16],["Deepak",18]]
df=pd.DataFrame(D)
print(df)

Output:

        0   1
0    Udai  17
1  Aditya  15
2  Aakash  16
3  Deepak  18


4.

#Create a DataFrame using list using labels
import pandas as pd
D=[["Udai",17],["Aditya",15],["Aakash",16],["Deepak",18]]
C=["Name","Age"]
I=[1,2,3,4]
df=pd.DataFrame(D,I,columns=C)
df.index.name="Roll No."
print(df)

Output:

            Name  Age
Roll No.             
1           Udai   17
2         Aditya   15
3         Aakash   16
4         Deepak   18


5.
#Create a DataFrame using Series

import pandas as pd
D1=pd.Series({'udai':65,'aditya':60,'aakash':70,'deepak':50})
D2=pd.Series({'udai':28,'aditya':30,'aakash':20,'deepak':10})
df=pd.DataFrame({"Marks":D1,"practical":D2})
print(df)


OR


import pandas as pd
D1={'udai':65,'aditya':60,'aakash':70,'deepak':50}
D2={'udai':28,'aditya':30,'aakash':20,'deepak':10}
S1=pd.Series(D1)
S2=pd.Series(D2)
df=pd.DataFrame({"Marks":S1,"practical":S2})
print(df)


Output:

        Marks  practical
udai       65         28
aditya     60         30
aakash     70         20
deepak     50         10


6.
#Create a DataFrame using Dictionary
import pandas as pd
I=['IP','Bio','Chemistry','Physics','English']
D={"2018":[50,60,70,80.5,90],"2019":[40,35,45,55,32], \
   "2020":[65,75,85,45,52],}
df=pd.DataFrame(D,I)
print(df)


Output:

           2018  2019  2020
IP         50.0    40    65
Bio        60.0    35    75
Chemistry  70.0    45    85
Physics    80.5    55    45
English    90.0    32    52

Tuesday, September 28, 2021

General Computer Questions - 1

 

1. Operating Systems for Computer or PC

  • MS-Windows
  • Unix
  • Linux
  • Ubuntu
  • Mac OS
  • Fedora
  • Chrome OS
  • Solaris


2. Mobile Operating System

  • Android
  • Apple iOS
  • Windows OS
  • Blackberry OS
  • Samsung BADA

3. Version of Windows OS

  • Windows 10
  • Windows 8
  • Windows 7
  • Windows XP
  • Windows 98

4. Version of Android OS.


Name

Internal codename

Version number(s)

Initial stable
release date

API level

Android 1.0

N/A

1.0

September 23, 2008

1

Android 1.1

Petit Four

1.1

February 9, 2009

2

Android Cupcake

Cupcake

1.5

April 27, 2009

3

Android Donut

Donut

1.6

September 15, 2009

4

Android Eclair

Eclair

2.0

October 27, 2009

5

2.0.1

December 3, 2009

6

2.1

January 11, 2010

7

Android Froyo

Froyo

2.2 – 2.2.3

May 20, 2010

8

Android Gingerbread

Gingerbread

2.3 – 2.3.2

December 6, 2010

9

2.3.3 - 2.3.7

February 9, 2011

10

Android Honeycomb

Honeycomb

3.0

February 22, 2011

11

3.1

May 10, 2011

12

3.2 - 3.2.6

July 15, 2011

13

Android Ice Cream Sandwich

Ice Cream Sandwich

4.0 – 4.0.2

October 18, 2011

14

4.0.3 - 4.0.4

December 16, 2011

15

Android Jelly Bean

Jelly Bean

4.1 – 4.1.2

July 9, 2012

16

4.2 - 4.2.2

November 13, 2012

17

4.3 - 4.3.1

July 24, 2013

18

Android KitKat

Key Lime Pie

4.4 – 4.4.4

October 31, 2013

19

4.4W - 4.4W.2

June 25, 2014

20

Android Lollipop

Lemon Meringue Pie

5.0 – 5.0.2

November 4, 2014

21

5.1 - 5.1.1

March 2, 2015

22

Android Marshmallow

Macadamia Nut Cookie

6.0 – 6.0.1

October 2, 2015

23

Android Nougat

New York Cheesecake

7.0

August 22, 2016

24

7.1 - 7.1.2

October 4, 2016

25

Android Oreo

Oatmeal Cookie

8.0

August 21, 2017

26

8.1

December 5, 2017

27

Android Pie

9

August 6, 2018

28

Android 10

Quince Tart

10

September 3, 2019

29

Android 11

Red Velvet Cake

11

September 8, 2020

30

Android 12

Snow Cone

12

TBA

31





5. Name of Antivirus Software:

  • Nortan
  • Kaspersky
  • Bit Defender
  • Avira
  • Avast
  • Quick Heal


6. Name of Virus:

  • ILOVEYOU
  • Morris Worm
  • SQL Slammer
  • Nimda
  • Creeper
  • Brain


7. Web Browser Names:

  • Google Chrome
  • Internet Explorer
  • Microsoft Edge
  • Mozilla Firefox
  • Opera Mini
  • UC Browser

8. Social Networking Websites

  • Facebook
  • Twitter
  • Instagram
  • LinkedIn
  • YouTube
  • Quora

9. Search Engine Name:

  • Google
  • Yahoo
  • Bing
  • Baidu
  • Ask.com

10. Utility Software:

  • Antivirus
  • File Management System
  • Disk Management tools
  • Compression tools
  • Disk cleanup tool
  • File Management System
  • Disk Defragmenter
  • Backup utility
  • Disk Cleaners