You are on page 1of 3

####2 table

i=1
while i<=10 :
print(2,"*",i,"=",2*i)
i = i+1

#####1 to 10 tables
i=1
while i<=10 :
j = 1
while j <=10:
print(i,"*",j,"=",i*j)
j = j+1
i = i+1

####printing max value in the list


max = 0
for i in [1,5,7,9,2] :
if max < i :
max = i
print ("Max value in the list" , max)

#####sum of the given numbers


sum = 0
for i in [1,5,7,9,2] :
sum = sum + i

print ("SUM OF THE GIVEN NUMBERS IS" , sum)

#####count even and odd


even = 0
odd = 0
for i in [1,3,5,4,6,9,11,13,46] :
if i % 2 == 0 :
even = even + 1
else :
odd = odd + 1

print("even no's count is" , even)


print("odd no's cout is", odd)

####create a file and write content

file1 = open("C:/Users/RAMAKRISHNA KOTA/Desktop/file1.txt", "w")


text = " iam Mr.Rama"
file1.write(text)

#### pritning alternative lines


file1 = open("C:/Users/RAMAKRISHNA KOTA/Desktop/file1.txt", "r")
file3 = open("C:/Users/RAMAKRISHNA KOTA/Desktop/file3.txt", "a")
text = file1.readlines()
i = 0
while i < len(text) :
file3.write(text[i])
i = i+2

####Functions :

def copy_file (source,dest) :


file1 = open(source,'r')
file2 = open(dest,'w')
text = file1.read()
file2.write(text)

copy_file("C:/Users/RAMAKRISHNA KOTA/Desktop/file1.txt","C:/Users/RAMAKRISHNA
KOTA/Desktop/text10.txt")

Function start with def


Functions in the class will be invoked with object of the class class
object.function

##### Programme_Pivoting excel####

import pandas as pd
from openpyxl.workbook import Workbook

df = pd.read_excel('D:/Alarm data_dashbaord.xlsb', sheet_name='(W)HW_Alarm%_data',


index_col=0, engine='pyxlsb')
table1 = pd.pivot_table(df, index=['Reserved_10'], values=['NE_ID'],
aggfunc=pd.Series.nunique, margins=True,
margins_name='Total')
table2 = pd.pivot_table(df, index=['Reserved_10'], values=['Alarm'],
aggfunc='count', margins=True,
margins_name='Total')
table3 = pd.pivot_table(df, index=['Circle'], values=['NE_ID'],
aggfunc=pd.Series.nunique, margins=True,
margins_name='Total')
table4 = pd.pivot_table(df, index=['Circle'], values=['Alarm'], aggfunc='count',
margins=True, margins_name='Total')
tablef1 = pd.concat([table1, table2], axis=1, join='inner')
tablef2 = pd.concat([table3, table4], axis=1, join='inner')
print(tablef1)
print(tablef2)
tablef1.to_excel("D:/Alarm1_dashboard.xlsx")
tablef2.to_excel("D:/Alarm2_dashboard.xlsx")

#########pivoting in csv######

import pandas as pd
df = pd.read_csv("D:\(W)HW_Alarm%_data.csv")
table1 = pd.pivot_table(df, index=['Week(c)'], values=['NE_ID'],
aggfunc=pd.Series.nunique, margins=True,margins_name='Total')
table2 = pd.pivot_table(df, index=['Week(c)'], values=['Specific_Problem'],
aggfunc='count', margins=True, margins_name='Total')

Result = pd.concat([table1,table2],axis=1,join='inner')
print(Result)

##### pivot in csv #####


import pandas as pd
df = pd.read_csv("D:\(W)HW_Alarm%_data.csv")
table1 = pd.pivot_table(df, index=['Week(c)'], values=['NE_ID'],
aggfunc=pd.Series.nunique, margins=True,margins_name='Total')
table2 = pd.pivot_table(df, index=['Week(c)'], values=['Specific_Problem'],
aggfunc='count', margins=True, margins_name='Total')

Result = pd.concat([table1,table2],axis=1,join='inner')
print(Result)

You might also like