diff --git a/DataStructure/queue.py b/DataStructure/queue.py index def1c7f..014f1a0 100644 --- a/DataStructure/queue.py +++ b/DataStructure/queue.py @@ -1,19 +1,19 @@ #function to add element at the end of list -def add_element(stack,x): - stack.append(x) +def add_element(queue,x): + queue.append(x) #function to remove last element from list -def delete_element(stack): - n = len(stack) +def delete_element(queue): + n = len(queue) if(n<=0): print("Queue empty....Deletion not possible") else: - del(stack[0]) + del(queue[0]) -#function to display stack entry -def display(stack): - if len(stack)<=0: +#function to display queue entry +def display(queue): + if len(queue)<=0: print("Queue empty...........Nothing to display") - for i in stack: + for i in queue: print(i,end=" ") #main program starts from here x=[] diff --git a/ModuleExamples/createModule.py b/ModuleExamples/createModule.py new file mode 100644 index 0000000..5733b43 --- /dev/null +++ b/ModuleExamples/createModule.py @@ -0,0 +1,23 @@ +def hello(): + for x in range(10): + print('hello', x, end =" ") + +def sum_digit(n): + sum1 = 0 + while n!=0: + sum1 += n%10 + n = n//10 + return sum1 + +def simple_interest(p,r,t): + return p*r*t/100 + +def area_triangle(base,height): + return base*height + +def isPrime(n): + found =0 + for x in range(2,(n//2)+1): + if n%x==0: + found=1 + return found \ No newline at end of file diff --git a/ModuleExamples/module_call.py b/ModuleExamples/module_call.py new file mode 100644 index 0000000..6868849 --- /dev/null +++ b/ModuleExamples/module_call.py @@ -0,0 +1,8 @@ +from createModule import isPrime + + +result = isPrime(11) +if result ==0: + print('Prime Number') +else: + print('Not a prime Number') \ No newline at end of file diff --git a/assignment_generator.py b/assignment_generator.py index 45b3799..6a46122 100644 --- a/assignment_generator.py +++ b/assignment_generator.py @@ -1,3 +1,4 @@ + import random unique=[] @@ -40,4 +41,4 @@ if(counter>=6): break - print(string) \ No newline at end of file + print(string) diff --git a/delete_record.py b/delete_record.py new file mode 100644 index 0000000..497c4af --- /dev/null +++ b/delete_record.py @@ -0,0 +1,29 @@ +import csv +name = input('Name to delete :') +# this is comment +# hello rakesh this is comment +""" this is multi line commnet""" + +records=[] +found =0 +file = open("student.csv","r") +reader = csv.DictReader(file) +for record in reader: + record = dict(record) + if(record['name']!=name): + records.append(dict(record)) + else: + found =1 +file.close() +# Remove the old file and create a new csv file +headers=['rollno','name','stream','fees'] +file = open("student.csv","w") +writer = csv.DictWriter(file,fieldnames =headers, lineterminator ='\n') +writer.writeheader() +writer.writerows(records) +file.close() + +if(found==0): + print(name, " does not exists") +else: + print(name," deleted successfully") diff --git a/fileHandling/Create_binary_file.py b/fileHandling/Create_binary_file.py index 3b23355..b9419b4 100644 --- a/fileHandling/Create_binary_file.py +++ b/fileHandling/Create_binary_file.py @@ -3,16 +3,16 @@ # Compiled on : 27-Nov-2019 import pickle -list = [] +list1 = [] while True: roll = input("Enter student Roll No:") sname = input("Enter student Name :") student = {"roll": roll, "name": sname} - list.append(student) + list1.append(student) choice = input("Want to add more record(y/n) :") if(choice == 'n'): break file = open("student.dat", "wb") -pickle.dump(list, file) +pickle.dump(list1, file) file.close() diff --git a/fileHandling/Update_binary_file_record.py b/fileHandling/Update_binary_file_record.py index 5d9893d..d235d19 100644 --- a/fileHandling/Update_binary_file_record.py +++ b/fileHandling/Update_binary_file_record.py @@ -4,8 +4,7 @@ import pickle -name = input('Enter name that you want to update in binary file :') - +name = input('Name to update :') file = open("student.dat", "rb+") list = pickle.load(file) diff --git a/fileHandling/binary_files/create_bn.py b/fileHandling/binary_files/create_bn.py new file mode 100644 index 0000000..3ee7385 --- /dev/null +++ b/fileHandling/binary_files/create_bn.py @@ -0,0 +1,13 @@ +import pickle +rec=[] +while True: + roll= int(input('Enter Name :')) + name=input('Enter your Name : ') + record = [roll, name] + rec.append(record) + choice=input('Add More(Y/N ) ? ') + if choice.upper() == 'N': +         break +f = open("student", "wb") +pickle.dump(rec, f) +f.close() diff --git a/fileHandling/csv Files/AddRecord.py b/fileHandling/csv Files/AddRecord.py new file mode 100644 index 0000000..0940960 --- /dev/null +++ b/fileHandling/csv Files/AddRecord.py @@ -0,0 +1,15 @@ +import csv + +rollno= int(input('Roll No :')) +name = input('Name :') +stream = input('Stream :') +fees = int(input('Fees :')) + +records = [rollno,name,stream,fees] + +f = open("student.csv", "a") +csvwriter = csv.writer(f, lineterminator='\n') +# csvwriter.writerow(header) +csvwriter.writerow(records) +f.close() +print("Record added ...") diff --git a/fileHandling/csv Files/deleteRecord_readerWriter.py b/fileHandling/csv Files/deleteRecord_readerWriter.py new file mode 100644 index 0000000..3332767 --- /dev/null +++ b/fileHandling/csv Files/deleteRecord_readerWriter.py @@ -0,0 +1,24 @@ +# program to update a record in csv file +import csv +name = input('Name to Delete :') +records = [] +found = 0 +file = open("student.csv", "r") +reader = csv.reader(file) +for record in reader: + if(record[1]!= name): + records.append(record) + found = 1 + +file.close() + +# Remove the old file and create a new csv file +file = open("student.csv", "w") +writer = csv.writer(file,lineterminator='\n') +writer.writerows(records) +file.close() + +if(found == 0): + print(name, " does not exists") +else: + print(name, " deleted successfully") diff --git a/fileHandling/csv Files/read_file.py b/fileHandling/csv Files/read_file.py new file mode 100644 index 0000000..e69de29 diff --git a/fileHandling/csv Files/readcsvFile.py b/fileHandling/csv Files/readcsvFile.py new file mode 100644 index 0000000..fc08f76 --- /dev/null +++ b/fileHandling/csv Files/readcsvFile.py @@ -0,0 +1,6 @@ +import csv +f = open(r"C:\Users\rakesh\Desktop\student.csv", "r") +data = csv.reader(f) +for record in data: + print(record) +f.close() diff --git a/fileHandling/csv Files/readcsvUsingDictReader.py b/fileHandling/csv Files/readcsvUsingDictReader.py new file mode 100644 index 0000000..83b0f46 --- /dev/null +++ b/fileHandling/csv Files/readcsvUsingDictReader.py @@ -0,0 +1,6 @@ +import csv +f = open(r"C:\Users\rakesh\Desktop\student.csv", "r") +data = csv.DictReader(f) +for record in data: + print(dict(record)) +f.close() diff --git a/fileHandling/csv Files/search_record.py b/fileHandling/csv Files/search_record.py new file mode 100644 index 0000000..5ea0b55 --- /dev/null +++ b/fileHandling/csv Files/search_record.py @@ -0,0 +1,15 @@ +import csv +name = input('Name to Search :') + +file = open('student.csv','r') +reader = csv.DictReader(file) +found =0 +for x in reader: + x = dict(x) + if(x['name']==name): + print(name,' found in CSV file..') + found =1 +file.close() + +if(found == 0): + print(name, ' not found....') \ No newline at end of file diff --git a/fileHandling/csv Files/search_record_reader.py b/fileHandling/csv Files/search_record_reader.py new file mode 100644 index 0000000..4cfc91a --- /dev/null +++ b/fileHandling/csv Files/search_record_reader.py @@ -0,0 +1,14 @@ +import csv +name = input('Name to Search :') + +file = open('student.csv', 'r') +reader =csv.reader(file) +found = 0 +for x in reader: + if(x[1] == name): + print(name, ' found in CSV file..') + found = 1 +file.close() + +if(found == 0): + print(name, ' not found....') diff --git a/fileHandling/csv Files/tempCodeRunnerFile.py b/fileHandling/csv Files/tempCodeRunnerFile.py new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/fileHandling/csv Files/tempCodeRunnerFile.py @@ -0,0 +1 @@ + diff --git a/fileHandling/csv Files/updateCSV.py b/fileHandling/csv Files/updateCSV.py new file mode 100644 index 0000000..c34da99 --- /dev/null +++ b/fileHandling/csv Files/updateCSV.py @@ -0,0 +1,31 @@ +# program to update a record in csv file +import csv +name = input('Name to Update :') +records = [] +found = 0 +file = open("student.csv", "r") +reader = csv.DictReader(file) +for record in reader: + record = dict(record) + if(record['name'] == name): + record = dict(record) + record['name'] =input('New Name:') + records.append(record) + found=1 + else: + records.append(dict(record)) +file.close() + +# Remove the old file and create a new csv file +pr +headers = ['rollno', 'name', 'stream', 'fees'] +file = open("student.csv", "w") +writer = csv.DictWriter(file, fieldnames=headers, lineterminator='\n') +writer.writeheader() +writer.writerows(records) +file.close() + +if(found == 0): + print(name, " does not exists") +else: + print(name, " updated successfully") diff --git a/fileHandling/csv Files/writeCSVFile.py b/fileHandling/csv Files/writeCSVFile.py new file mode 100644 index 0000000..b390e3e --- /dev/null +++ b/fileHandling/csv Files/writeCSVFile.py @@ -0,0 +1,15 @@ +import csv +records =[ + ["ID", "name", "Price", "Qty"], + ["102","LG Monitor","6500","20"], + ["103","KeyBoard","1350","156"], + ["105","Hp Mouse","650","120"], + ["106","Speaker","1670","136"] +] + +f = open("stock.csv","w") +csvwriter = csv.writer(f,lineterminator="\n") +# csvwriter.writerow(header) +csvwriter.writerows(records) +f.close() +print("Check your file now....") diff --git a/fileHandling/csv Files/writeCsvDictWriter.py b/fileHandling/csv Files/writeCsvDictWriter.py new file mode 100644 index 0000000..99cfb7d --- /dev/null +++ b/fileHandling/csv Files/writeCsvDictWriter.py @@ -0,0 +1,15 @@ +import csv +headers =['rollno','name','stream','fees'] +records = [ + {'fees': 2356,'rollno': 12, 'name': 'surendra', 'stream': 'Humanities', }, + {'rollno': 13, 'stream': 'Humanities', 'fees': 2356,'name': 'Ashok', }, + {'rollno':15,'name':'Nipun','stream':'Humanities','fees':2356}, + {'rollno': 22, 'name': 'Ayush Negi', 'fees': 2356,'stream': 'Science', }, +] + +f = open("student.csv", "w") +writer = csv.DictWriter(f, fieldnames = headers, lineterminator='\n') +writer.writeheader() +writer.writerows(records) +f.close() +print("Check your file now....") diff --git a/fileHandling/csvReader.py b/fileHandling/csvReader.py index a20fa03..273db00 100644 --- a/fileHandling/csvReader.py +++ b/fileHandling/csvReader.py @@ -1,3 +1,5 @@ + + import csv import xlwt from tabulate import tabulate diff --git a/fileHandling/read_binary_file.py b/fileHandling/read_binary_file.py index 4faf422..becf9fc 100644 --- a/fileHandling/read_binary_file.py +++ b/fileHandling/read_binary_file.py @@ -6,5 +6,6 @@ file = open("student.dat", "rb") list = pickle.load(file) -print(list) +for x in list: + print(x['roll'],x['name']) file.close() diff --git a/fileHandling/search_in_binary_file.py b/fileHandling/search_in_binary_file.py index b6139f1..cef43b9 100644 --- a/fileHandling/search_in_binary_file.py +++ b/fileHandling/search_in_binary_file.py @@ -3,15 +3,13 @@ # Compiled on : 8-July-2018 import pickle - -name = input('Enter name that you want to search in binary file :') - +name = input('Name to search :') file = open("student.dat", "rb") -list = pickle.load(file) +list1 = pickle.load(file) file.close() found = 0 -for x in list: +for x in list1: if name in x['name']: found = 1 print("Found in binary file" if found == 1 else "Not found") diff --git a/matplotlib/bar_Graph.py b/matplotlib/bar_Graph.py index 6851d0b..a61f819 100644 --- a/matplotlib/bar_Graph.py +++ b/matplotlib/bar_Graph.py @@ -1,11 +1,12 @@ # program to print bar graph on the screen # made by : rakesh kumar +import numpy as np import matplotlib.pyplot as plt -x = ['Delhi', 'Banglore', 'Chennai', 'Pune'] -y = [250, 300, 260, 400] +city = ['Delhi', 'Banglore', 'Chennai', 'Pune'] +sales = [250, 300, 260, 400] plt.xlabel('City') plt.ylabel('Sales in Million') plt.title('Sales Recorded in Major Cities') -plt.bar(x, y) +plt.bar(city, sales) plt.show() diff --git a/matplotlib/box_plot1.py b/matplotlib/box_plot1.py new file mode 100644 index 0000000..0b80b7d --- /dev/null +++ b/matplotlib/box_plot1.py @@ -0,0 +1,5 @@ +import matplotlib.pyplot as plt +x = [1, 3, 4, 7, 8, 8, 9] +plt.boxplot(x) +plt.grid() +plt.show() diff --git a/matplotlib/box_plot2.py b/matplotlib/box_plot2.py new file mode 100644 index 0000000..cba19fc --- /dev/null +++ b/matplotlib/box_plot2.py @@ -0,0 +1,7 @@ +import matplotlib.pyplot as plt +list1 = [10, 33, 43, 74, 84, 8, 9,35,63,5,3,67,8,78,35,2,57,7,78,34,67,34] +list2 = [23,3,5,67,67,78,98,90,100,12,45,67,89,45,56,78,9,23,69,56,23,5] +plt.boxplot([list1,list2],labels=['Girls','Boys']) +plt.grid() +plt.legend() +plt.show() diff --git a/matplotlib/boxplot.py b/matplotlib/boxplot.py new file mode 100644 index 0000000..3c85a31 --- /dev/null +++ b/matplotlib/boxplot.py @@ -0,0 +1,8 @@ +import matplotlib.pyplot as plt +import numpy as np +import numpy as np +x = np.arange(1,100) +y = np.arange(101,200) +z= np.arange(201,250) +plt.boxplot([x,y,z]) +plt.show() \ No newline at end of file diff --git a/matplotlib/frequency_polygon.py b/matplotlib/frequency_polygon.py index d820b59..7ddb20b 100644 --- a/matplotlib/frequency_polygon.py +++ b/matplotlib/frequency_polygon.py @@ -1 +1,22 @@ import matplotlib.pyplot as plt +<<<<<<< HEAD +======= +from numpy import linspace,pi,sin,cos,tan + +#multiple figures +data=[1,2,3,4,5, + 10,11,12,14,15,18,16,14,13,12,19,20,16,14,19, + 22, 21, 22, 23, 24, 25, 23, 26, 28, 26,27,25,28,29,30, + 32,33,37,38,38,39,34,36, + 42,43,45,46,48,46,49,50,43,42,44,45,47,49,50,49,48,42,46,41,45,46,48,45,44, + 51,52,54,55,53,58,57,59,60,52,51,54,53 + ] +frequency = [5,15,18,8,25,13] +x = [5,15,25.5,35.5,45.5,55.5] + + +plt.figure(1) +plt.hist(data,bins=[0,10,20,30,40,50,60],color="green") +plt.scatter(frequency,x) +plt.show() +>>>>>>> da25a2a32ac30d0980ed6d1d3ad58008d8ff0b21 diff --git a/matplotlib/histogram.py b/matplotlib/histogram.py new file mode 100644 index 0000000..4f78063 --- /dev/null +++ b/matplotlib/histogram.py @@ -0,0 +1,11 @@ +import matplotlib.pyplot as plt +sugar_men = [121,153,243,33,95,138,339,150,252,156,143,118] +sugar_women = [67,101,120,135,180,125,68,95,92,102,47,78,135,225] +sugar_child =[120,89,123,145,100,89,135,120,102,125,123,170,180] +plt.hist([sugar_men, sugar_women,sugar_child], bins=[100, 130, 150, 200], + rwidth=0.80, color=['green', 'orange','purple'], label=['Men', 'Women', 'children']) +plt.legend() +plt.xlabel('Sugar Readings') +plt.ylabel('No of Patient') +plt.title('Sugar Patient Stats') +plt.show() diff --git a/matplotlib/histogram1.py b/matplotlib/histogram1.py new file mode 100644 index 0000000..86b0bfb --- /dev/null +++ b/matplotlib/histogram1.py @@ -0,0 +1,4 @@ +import matplotlib.pyplot as plt +x=[12, 15, 23, 33, 35, 38, 39, 50, 52, 56, 43, 18] +plt.hist(x, bins=[10, 20, 30, 40, 50, 60],color="red",rwidth=0.80) +plt.show() \ No newline at end of file diff --git a/matplotlib/line_graph.py b/matplotlib/line_graph.py index fc06b90..786ce57 100644 --- a/matplotlib/line_graph.py +++ b/matplotlib/line_graph.py @@ -1,12 +1,13 @@ -# program to print scatter graph on the screen +# program to print line graph on the screen # made by : rakesh kumar import matplotlib.pyplot as plt import numpy as np -x = ['Delhi', 'Banglore', 'Chennai', 'Pune'] -y = [250, 300, 260, 400] -plt.xlabel('City') -plt.ylabel('Sales in Million') -plt.title('Sales Recorded in Major Cities') +x = ['week-1', 'week-2', 'week-3', 'week-4',"Week-6","Week-6","week-7","week-8"] +y = [1250, 1300, 1260, 1400,2420,3180,6550,1220] plt.plot(x, y) +plt.xlabel('Week wise Sales') +plt.ylabel('No of Unit Sold') +plt.title('Sales of Electronics in Deepawali') +plt.grid() plt.show() diff --git a/matplotlib/multiple_bar2.py b/matplotlib/multiple_bar2.py new file mode 100644 index 0000000..ce4185f --- /dev/null +++ b/matplotlib/multiple_bar2.py @@ -0,0 +1,16 @@ +import matplotlib.pyplot as plt +import numpy as np + +girls =(79,67,82) +boys = (89,78,56) +y_pos = np.arange(3) + +width=0.30 + +plt.bar(width+y_pos,girls,width,color='r',label="Girls") +plt.bar(2*width+y_pos,boys,width,color='green',label="boys") + +plt.xlabel('Students') +plt.ylabel('Marks') +plt.legend() +plt.show() diff --git a/matplotlib/multiple_barGraph.py b/matplotlib/multiple_barGraph.py new file mode 100644 index 0000000..597b72f --- /dev/null +++ b/matplotlib/multiple_barGraph.py @@ -0,0 +1,28 @@ +import matplotlib.pyplot as plt +import numpy as np + +names = ["Arushi","Pratham","Mannat"] +marks1 = (82, 80, 63) +marks2 = (98, 73, 30) +marks3 =(78,87,45) +marks4 =(99,92,90) +final = (99,67,78) + +x = np.arange(len(marks1)) +width = 0.15 + +fig, axes = plt.subplots(ncols=1, nrows=1) + +axes.bar(x, marks1, width, align='edge',color="orange", label="UT-1") +axes.bar(x+width, marks2, width, align='edge', color='purple', label="UT-2") +axes.bar(x+2*width, marks3, width, align='edge', color='green', label="Half Yearly") +axes.bar(x+3*width, marks4, width, align='edge', color='red', label="PreBoard") +axes.bar(x+4*width, final, width, align='edge', color='blue', label="Final") + +axes.set_xticks(x) +axes.set_xticklabels(names) +plt.xlabel('Student Names') +plt.ylabel('Marks Obtained') +plt.title('Student Performance') +plt.legend() +plt.show() \ No newline at end of file diff --git a/matplotlib/multiple_graph.py b/matplotlib/multiple_graph.py new file mode 100644 index 0000000..eeb81cb --- /dev/null +++ b/matplotlib/multiple_graph.py @@ -0,0 +1,14 @@ +import matplotlib.pyplot as plt +plt.figure(1) # the first figure +plt.subplot(211) # the first subplot in the first figure +plt.plot([1, 2, 3]) +plt.subplot(212) # the second subplot in the first figure +plt.plot([4, 5, 6]) +plt.figure(2) # a second figure +plt.plot([4, 5, 6]) # creates a subplot(111) by default +plt.figure(1) # figure 1 current; subplot(212) still current +plt.subplot(211) # make subplot(211) in figure1 current +plt.title('Easy as 1,2,3') # subplot 211 title +plt.subplot(212) +plt.title('second plot title') +plt.show() \ No newline at end of file diff --git a/matplotlib/multiple_line.py b/matplotlib/multiple_line.py new file mode 100644 index 0000000..e543ecb --- /dev/null +++ b/matplotlib/multiple_line.py @@ -0,0 +1,17 @@ +import matplotlib.pyplot as plt + +names =("rakesh","mannat","pratham","pushkar") +mark1 =(56,78,56,34) +mark2 =(78,58,45,89) +mark3= (90,78,89,56) + +plt.plot(names,mark1,label="UT-1") +plt.plot(names,mark2,label="UT-2") +plt.plot(names,mark3,label="UT-3") + +plt.grid(True) +plt.xlabel('Names') +plt.ylabel('Marks') +plt.title('Student Performance') +plt.legend() +plt.show() diff --git a/matplotlib/scatter_graph.py b/matplotlib/scatter_graph.py index 3c85a31..28e60bb 100644 --- a/matplotlib/scatter_graph.py +++ b/matplotlib/scatter_graph.py @@ -1,8 +1,7 @@ import matplotlib.pyplot as plt -import numpy as np -import numpy as np -x = np.arange(1,100) -y = np.arange(101,200) -z= np.arange(201,250) -plt.boxplot([x,y,z]) +x = [5, 7, 8, 7, 2, 17, 2, 9, 4, 11, 12, 9, 6] +y = [99, 86, 87, 88, 111, 86, 103, 87, 94, 78, 77, 85, 86] + +plt.scatter(x,y) +plt.grid() plt.show() \ No newline at end of file diff --git a/matplotlib/scatter_graph_random_dots.py b/matplotlib/scatter_graph_random_dots.py new file mode 100644 index 0000000..3bfce11 --- /dev/null +++ b/matplotlib/scatter_graph_random_dots.py @@ -0,0 +1,8 @@ +import numpy +import matplotlib.pyplot as plt + +x = numpy.random.normal(5.0, 1.0, 1000) +y = numpy.random.normal(10.0, 2.0, 1000) + +plt.scatter(x, y) +plt.show() diff --git a/matplotlib/simpleplt.py b/matplotlib/simpleplt.py index 9cfe747..3099d40 100644 --- a/matplotlib/simpleplt.py +++ b/matplotlib/simpleplt.py @@ -1,3 +1,12 @@ import matplotlib.pyplot as plt +<<<<<<< HEAD plt plt.show() +======= +import numpy as np +x = np.linspace(0,2.0*np.pi,101) +# print(x) +y = np.sin(x) +plt.plot(x,y,color="red",linestyle="--",linewidth="5") +plt.show() +>>>>>>> da25a2a32ac30d0980ed6d1d3ad58008d8ff0b21 diff --git a/matplotlib/stacked_bar_graph.py b/matplotlib/stacked_bar_graph.py new file mode 100644 index 0000000..64b2039 --- /dev/null +++ b/matplotlib/stacked_bar_graph.py @@ -0,0 +1,21 @@ +import numpy as np +import matplotlib.pyplot as plt + + +N = 5 +menMeans = (20, 35, 30, 35, 27) +womenMeans = (25, 32, 34, 20, 25) +menStd = (2, 3, 4, 1, 2) +womenStd = (3, 5, 2, 3, 3) +ind = np.arange(N) # the x locations for the groups +width = 0.35 # the width of the bars: can also be len(x) sequence + +p1 = plt.bar(ind, menMeans, width, yerr=menStd) +p2 = plt.bar(ind, womenMeans, width,bottom=menMeans, yerr=womenStd) + +plt.ylabel('Scores') +plt.title('Scores by group and gender') +plt.xticks(ind, ('G1', 'G2', 'G3', 'G4', 'G5')) +plt.yticks(np.arange(0, 81, 10)) +plt.legend((p1[0], p2[0]), ('Men', 'Women')) +plt.show() \ No newline at end of file diff --git a/matplotlib/tempCodeRunnerFile.py b/matplotlib/tempCodeRunnerFile.py index 99c9799..bd57c8a 100644 --- a/matplotlib/tempCodeRunnerFile.py +++ b/matplotlib/tempCodeRunnerFile.py @@ -1 +1,4 @@ -,autopct='%1.2f' \ No newline at end of file +import matplotlib.pyplot as plt +x=[12, 15, 23, 33, 35, 38, 39, 50, 52, 56, 43, 18] +plt.hist(x, bins=[10, 20, 30, 40, 50, 60],rwidth=0.80) +plt.show() \ No newline at end of file diff --git a/pandas/dataFrames/tempCodeRunnerFile.py b/pandas/dataFrames/tempCodeRunnerFile.py new file mode 100644 index 0000000..4671fa3 --- /dev/null +++ b/pandas/dataFrames/tempCodeRunnerFile.py @@ -0,0 +1 @@ +marks = pd.Series({'rakesh':56,'anuj':89,'Bhumi':90,'Jagdev':80}) \ No newline at end of file diff --git a/pandas/seletion_slicing.py b/pandas/seletion_slicing.py new file mode 100644 index 0000000..242316a --- /dev/null +++ b/pandas/seletion_slicing.py @@ -0,0 +1,8 @@ +import pandas as pd +import numpy as np + +s = pd.Series(np.arange(2,20,2)) +print(s[2]) # show value at index 2 +print(s[1:]) # display all element from 1 index onward +print(s[:4]) # display values present at index 0,1,2,3 +print(s[1::2]) # display value present at index 1,3,5,7 \ No newline at end of file diff --git a/pandas/series1.py b/pandas/series1.py new file mode 100644 index 0000000..a0a0b17 --- /dev/null +++ b/pandas/series1.py @@ -0,0 +1,6 @@ +import pandas as pd +import numpy as np + +#blank series +s = pd.Series() +print(s) diff --git a/pandas/series10.py b/pandas/series10.py new file mode 100644 index 0000000..95a931b --- /dev/null +++ b/pandas/series10.py @@ -0,0 +1,6 @@ + +# series with string and index also in string +import pandas as pd +s = pd.Series('Welcome to DAV Chander Nagar', index=[ + 'rakesh', 'arushi', 'mannat', 'vinay', 'pratham']) +print(s) diff --git a/pandas/series11.py b/pandas/series11.py new file mode 100644 index 0000000..4d3f0d9 --- /dev/null +++ b/pandas/series11.py @@ -0,0 +1,4 @@ +# series with range and for loop +import pandas as pd +s = pd.Series(range(5), index=[x for x in 'abcde']) +print(s) diff --git a/pandas/series12.py b/pandas/series12.py new file mode 100644 index 0000000..1764a64 --- /dev/null +++ b/pandas/series12.py @@ -0,0 +1,6 @@ +# series with two different lists +import pandas as pd +names = ['rakesh', 'vishank', 'nikunj', 'unnati', 'vipul'] +city = ['GZB', 'Delhi', 'Meerut', 'Pune', 'Panji'] +s = pd.Series(names, index=city) +print(s) \ No newline at end of file diff --git a/pandas/series13.py b/pandas/series13.py new file mode 100644 index 0000000..92de67a --- /dev/null +++ b/pandas/series13.py @@ -0,0 +1,6 @@ + +#series with Nan values of numpy +import pandas as pd +import numpy as np +s = pd.Series([10, 20, 30, np.NaN, -34.5, 6]) +print(s) diff --git a/pandas/series14.py b/pandas/series14.py new file mode 100644 index 0000000..e23beb9 --- /dev/null +++ b/pandas/series14.py @@ -0,0 +1,6 @@ +#series from a python Dictionary +import pandas as pd +dict1 = {'name': 'rakesh', 'roll': 20, 'city': 'Gzb', + 'age': 40, 'profession': 'Teaching'} +s = pd.Series(dict1) +print(s) diff --git a/pandas/series15.py b/pandas/series15.py new file mode 100644 index 0000000..10a82e1 --- /dev/null +++ b/pandas/series15.py @@ -0,0 +1,6 @@ +# series using a mathematical expression +import pandas as pd +import numpy as np +data = np.arange(10, 15) +s = pd.Series(data**2, index=data) +print(s) diff --git a/pandas/series2.py b/pandas/series2.py new file mode 100644 index 0000000..1139ddc --- /dev/null +++ b/pandas/series2.py @@ -0,0 +1,6 @@ +import pandas as pd +import numpy as np + +#series with numbers +s = pd.Series([10, 20, 30, 40, 50]) +print(s) diff --git a/pandas/series3.py b/pandas/series3.py new file mode 100644 index 0000000..e9c75d5 --- /dev/null +++ b/pandas/series3.py @@ -0,0 +1,3 @@ +import pandas as pd +s = pd.Series([10, 20, 30, 40, 50], index=[1, 2, 3, 4, 5]) +print(s) diff --git a/pandas/series4.py b/pandas/series4.py new file mode 100644 index 0000000..283b5d8 --- /dev/null +++ b/pandas/series4.py @@ -0,0 +1,4 @@ +#series with numbers and char index +import pandas as pd +s = pd.Series([10, 20, 30, 40, 50], index=['a', 'b', 'c', 'd', 'e']) +print(s) diff --git a/pandas/series5.py b/pandas/series5.py new file mode 100644 index 0000000..4bc99cb --- /dev/null +++ b/pandas/series5.py @@ -0,0 +1,4 @@ +#series with constant values +import pandas as pd +s = pd.Series(55, index=[1, 2, 3, 4, 5, 6]) +print(s) diff --git a/pandas/series6.py b/pandas/series6.py new file mode 100644 index 0000000..c9bd67b --- /dev/null +++ b/pandas/series6.py @@ -0,0 +1,4 @@ +#series with constant and python function +import pandas as pd +s = pd.Series(34, index=range(100)) +print(s) diff --git a/pandas/series7.py b/pandas/series7.py new file mode 100644 index 0000000..f54e390 --- /dev/null +++ b/pandas/series7.py @@ -0,0 +1,4 @@ +# series with python function +import pandas as pd +s = pd.Series(range(2, 89)) +print(s) diff --git a/pandas/series8.py b/pandas/series8.py new file mode 100644 index 0000000..8d254ee --- /dev/null +++ b/pandas/series8.py @@ -0,0 +1,4 @@ +# series with float values +import pandas as pd +s=pd.Series([10, 20, 30, 40.5, 50]) +print(s) diff --git a/pandas/series9.py b/pandas/series9.py new file mode 100644 index 0000000..886ab28 --- /dev/null +++ b/pandas/series9.py @@ -0,0 +1,4 @@ +# series with string type values +import pandas as pd +s = pd.Series('Welcome to DAV Chander Nagar', index=[1, 2, 3, 4, 5, 6]) +print(s) diff --git a/pandas/series_methods.py b/pandas/series_methods.py new file mode 100644 index 0000000..7e95ee7 --- /dev/null +++ b/pandas/series_methods.py @@ -0,0 +1,17 @@ +import pandas as pd +marks=[] +for i in range(5): + n = int(input("Marks :")) + marks.append(n) + +s = pd.Series(marks) +#print(s) +print(s.sort_values(ascending=True)) # False for Descending +lar = s.max() +low = s.min() +summ = s.sum() +noe = len(s) +print('Maximum values :', lar) +print('Minimum values :', low) +print('Sum of values :', summ) +print('Average value ', summ/noe) \ No newline at end of file diff --git a/pandas/series_object.py b/pandas/series_object.py index 61ff187..2d61d00 100644 --- a/pandas/series_object.py +++ b/pandas/series_object.py @@ -9,8 +9,6 @@ # series.hasnans - return true if there are any Nan value # series.empty - return true if series object is empty - - import pandas as pd s= pd.Series(range(3,30,3)) diff --git a/pandas/series_slicing2.py b/pandas/series_slicing2.py new file mode 100644 index 0000000..3c30bee --- /dev/null +++ b/pandas/series_slicing2.py @@ -0,0 +1,8 @@ +import pandas as pd +import numpy as np + +s = pd.Series(np.arange(2, 20, 2),index=[x for x in "abcdefghi"]) +print(s[2]) # show value at index 2 +print(s[1:]) # display all element from 1 index onward +print(s[:4]) # display values present at index 0,1,2,3 +print(s[1::2]) # display value present at index 1,3,5,7 diff --git a/pandas/tempCodeRunnerFile.py b/pandas/tempCodeRunnerFile.py new file mode 100644 index 0000000..e8a486f --- /dev/null +++ b/pandas/tempCodeRunnerFile.py @@ -0,0 +1,13 @@ +# retirve values from pandas series using head() and tail() function + +import pandas as pd +s= pd.Series(range(1,1000,5)) +#print top 5 entries of the series +print(s.head()) +#print top 2 entries of the series +print(s.head(2)) + +#print last 5 entries of the series +print(s.tail()) +# print last 2 entries of the series +print(s.tail(2)) \ No newline at end of file diff --git a/pandas/vector_operation_series.py b/pandas/vector_operation_series.py index 8089557..27485e3 100644 --- a/pandas/vector_operation_series.py +++ b/pandas/vector_operation_series.py @@ -1,6 +1,6 @@ import pandas as pd -s = pd.Series(range(2,40)) -print("Print True if Values Greater than 12 else faslse") +s = pd.Series(range(2,20)) +print("Print True if Values Greater than 12 else false") print(s>12) print("Print values greater than 12") diff --git a/stock.csv b/stock.csv new file mode 100644 index 0000000..2db755a --- /dev/null +++ b/stock.csv @@ -0,0 +1,5 @@ +ID,name,Price,Qty +102,LG Monitor,6500,20 +103,KeyBoard,1350,156 +105,Hp Mouse,650,120 +106,Speaker,1670,136 diff --git a/student.csv b/student.csv new file mode 100644 index 0000000..277c95e --- /dev/null +++ b/student.csv @@ -0,0 +1,5 @@ +rollno,name,stream,fees +12,surendra,Humanities,2356 +13,Ashok Goyal,Humanities,2356 +15,Nipun,Humanities,2356 +22,Ayush Negi,Science,2356 \ No newline at end of file diff --git a/student.dat b/student.dat index ce6b3f1..e69de29 100644 Binary files a/student.dat and b/student.dat differ diff --git a/tempCodeRunnerFile.py b/tempCodeRunnerFile.py index 92b2adf..d27822c 100644 --- a/tempCodeRunnerFile.py +++ b/tempCodeRunnerFile.py @@ -1 +1,2 @@ -target_list \ No newline at end of file +file = open("student.dat","w") +writer = csv.DictWriter(file,fieldnames ="", lineterminator ='\n') \ No newline at end of file diff --git a/update_readerWriter.py b/update_readerWriter.py new file mode 100644 index 0000000..aa3ac5c --- /dev/null +++ b/update_readerWriter.py @@ -0,0 +1,28 @@ +# program to update a record in csv file +import csv +name = input('Name to Update :') +records = [] +found = 0 +file = open("student.csv", "r") +reader = csv.reader(file) +for record in reader: + if(record[1] == name): + record[1] = input('New Name:') + records.append(record) + found = 1 + else: + records.append(record) +file.close() + +# Remove the old file and create a new csv file +headers = ['rollno', 'name', 'stream', 'fees'] +file = open("student.csv", "w") +writer = csv.writer(file, lineterminator='\n') +writer.writerow(headers) +writer.writerows(records) +file.close() + +if(found == 0): + print(name, " does not exists") +else: + print(name, " updated successfully")