0% found this document useful (0 votes)
9 views3 pages

Python Exercises

Uploaded by

rajaduraicse1993
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views3 pages

Python Exercises

Uploaded by

rajaduraicse1993
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

pip install matplotlib

Pip install numpy


Pip install pandas
Pip install scikit-learn

PYTHON EXERCISES
Var1 = "The Quick Brown Fox Jumps Over The Lazy Dog"
cntCaps = 0
cntSmall = 0
splChar = 0

for letter in Var1:

if ord(letter) >= 65 and ord(letter) <= 90:


cntCaps += 1
elif ord(letter) >= 97 and ord(letter) <= 122:
cntSmall += 1
else:
splChar += 1
print("No of Caps are ",cntCaps," no of smalls are", cntSmall,"and no of special char
",splChar)

import pandas as pd
list = ['R','a','j','a','d','u','r','a','i']
ser = pd.Series(list)
print(ser)

import pandas as pd
import numpy as np

data = np.array(['R','a','j','a','d','u','r','a','i'])
ser = pd.Series(data)
print(ser)

import pandas as pd
data = {'a':0.,'b':1.,'c':2.,'d':3.0}
s = pd.Series(data)
print(s)

import pandas as pd
s = pd.Series(5,index=[0,1,2,3])
print (s)
import pandas as pd
import numpy as np
data = np.array(['R','a','j','a','d','u','r','a','i'])
ser = pd.Series(data)
print(ser[:4])
print(ser[-3:])

import numpy as np
import pandas as pd
data = np.array(['R','A','J','A','D','U','R','A','I'])
ser = pd.Series(data,index=[10,11,12,13,14,15,16,17,18])
print(ser[3:5])

ser2 = pd.Series(data,index=['R','A','J','A','D','U','R','A','I'])
print(ser2[3:5])

import numpy as np
import pandas as pd

data = np.array(['R','A','J','A','D','U','R','A','I'])
ser2 = pd.Series(data,index=['a','b','c','d','e','f','g','h','i'])
print(ser2['a'])
print()
print(ser2[['a','d','c']])

import numpy as np
import pandas as pd

data = np.array(['R','A','J','A','D','U','R','A','I'])
ser1 = pd.Series(data,index = [10,11,12,13,14,15,16,17,18])
print(ser1.loc[13:15])

print()

ser2 = pd.Series(data, index = ['R','A','J','A','D','U','R','A','I'])


print(ser2.loc['D':'I'])

import numpy as np
import pandas as pd

data = np.array(['R','A','J','A','D','U','R','A','I'])
ser1 = pd.Series(data,index = [10,11,12,13,14,15,16,17,18])
print(ser1.iloc[3:5])

print()

ser2 = pd.Series(data, index = ['R','A','J','A','D','U','R','A','I'])


print(ser2.iloc[3:5])

import numpy as np
import pandas as pd

df = pd.DataFrame()
print(df)
print()
arr = np.array([[1,2,3,],[4,5,6]])
print (pd.DataFrame(arr))
print()
my_dict = {1:['1','3'],2:['1','2'],3:['2','4']}
print(pd.DataFrame(my_dict))
print()
my_df = pd.DataFrame(data = [4,5,6,7], index = range(0,4), columns=['A'])
print(pd.DataFrame(my_df))

import numpy as np
import pandas as pd

my_series = pd.Series({"UK":"London","IND":"New Delhi","USA":"Washington","Belgium":"Brussels"})


df = pd.DataFrame(my_series)
print(df)
print()
print(df.head())

print()
data = np.array([['','Col1','Col2'],['Row1',1,2],['Row2',3,4]])
print(pd.DataFrame(data = data[1:,1:], index = data[1:,0],columns = data[0,1:]))

print()
dict = {"country":["Brazil","Russia","India","China","South Africa"], "capital":
["Brasilia","Moscow","New Delhi","Beijing","Pretoria"], "area":[8.526, 17.10,3.286,9.597,1.221],
"population":[200.4,143.5,1252,1357,52.98]}
brics = pd.DataFrame(dict)
print(brics)
n = int(input())
if n % 2 == 1 or (n >= 6 and n <= 20):
print("Weird")
else:
print("Not Weird")

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy