Professional Documents
Culture Documents
import math
math.pow(x,y)
Access Math inbuilt functions math.sqrt(x)
String Manipulation
Print first character of string s print(s[0]) —forward index
Length of string s len(s)
Print the second last character using backward index print(s[-2])
Print alternating characters in s print(s[::2])
Print s in reverse print(s[::-1])
string to UPPER/LOWER case s.upper(), s.lower()
Split the sentence when there is ‘,’ s.split(',')
Eg
math.pow(x,y)
math.sqrt(x)
Dictionary
A dictionary is a collection which is unordered, changeable and indexed. In Python dictionaries are written with
Given dictionary
qualifier_2 = {'KKR': {'Chris Lynn': 4, 'Sunil Narine': 10, 'Gautam Gambhir (c)': 12, 'Robin Uthappa (wk)': 1, 'Is
'Suryakumar Yadav': 31, 'Piyush Chawla': 2, 'Nathan Coulter-Nile': 6, 'Umesh Yadav': 2, 'Ankit Rajpoot': 4, 'Ext
Simmons': 3, 'Parthiv Patel (wk)': 14, 'Ambati Rayudu': 6, 'Rohit Sharma (c)': 26, 'Krunal Pandya': 45, 'Kieron
KKR and MI are keys and others are values
Funtion
Access a value when you know the key
unil Narine': 10, 'Gautam Gambhir (c)': 12, 'Robin Uthappa (wk)': 1, 'Ishank Jaggi': 28, 'Colin Grandhomme': 0,
: 2, 'Nathan Coulter-Nile': 6, 'Umesh Yadav': 2, 'Ankit Rajpoot': 4, 'Extra runs': 7, 'Total batted': 10}, 'MI': {'Lendl
mbati Rayudu': 6, 'Rohit Sharma (c)': 26, 'Krunal Pandya': 45, 'Kieron Pollard': 9, 'Extra runs': 7, 'Total batted': 6}}
es
code
qualifier_2["KKR"]
for i in qualifier_2:
print(i)
print(x)
for x, y in qualifier_2.items():
print(x, y)
len(qualifier_2)
dhomme': 0,
0}, 'MI': {'Lendl
Total batted': 6}}
Eg
x---keys
y---values
ideal way of loading text data with white spaces as a delimiter
parameter would you use if you want to load data from line no 5 of the csv
load a csv file into pandas data frame with a different set of column names (‘a’,’b’,’c’)?
convert a pandas data frame to csv format?