0% found this document useful (0 votes)
4 views15 pages

NumPy and Pandas Programming Guide

The document contains a series of Python programs demonstrating the use of NumPy, Pandas, Matplotlib, and Tkinter libraries. It includes examples of array creation, basic operations, matrix manipulation, data visualization, and GUI components. Each section provides code snippets along with explanations of the output.

Uploaded by

expertcoding63
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)
4 views15 pages

NumPy and Pandas Programming Guide

The document contains a series of Python programs demonstrating the use of NumPy, Pandas, Matplotlib, and Tkinter libraries. It includes examples of array creation, basic operations, matrix manipulation, data visualization, and GUI components. Each section provides code snippets along with explanations of the output.

Uploaded by

expertcoding63
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

1.

Program to create a NumPy array and display its properties


import numpy as np

arr = [Link]([[1, 2, 3],


[4, 5, 6]])

print("Array:", arr)
print("Type:", type(arr))
print("Dimensions:", [Link])
print("Shape:", [Link])
print("Size:", [Link])
print("Data type:", [Link])

2. NumPy basic operations on a single array


import numpy as np

a = [Link]([1, 2, 5, 3])

print("Add 1:", a + 1)
print("Subtract 3:", a - 3)
print("Multiply by 10:", a * 10)
print("Square:", a ** 2)

3. Program to transpose a matrix


import numpy as np

a = [Link]([[1, 2, 3],
[3, 4, 5],
[9, 6, 0]])

print("Original matrix:")
print(a)

print("Transpose of matrix:")
print(a.T)

4. NumPy unary operations (min, max, sum)


import numpy as np

arr = [Link]([[5, 6],


[4, 7],
[3, 9]])

print("Maximum element:", [Link]())


print("Row-wise minimum:", [Link](axis=1))
print("Column-wise minimum:", [Link](axis=0))
print("Sum of all elements:", [Link]())

5. NumPy binary operations (addition & multiplication)


import numpy as np

a = [Link]([[1, 2],
[4, 5]])

b = [Link]([[4, 3],
[2, 1]])

print("Array sum:")
print(a + b)
print("Element-wise multiplication:")
print(a * b)

print("Matrix multiplication:")
print([Link](b))

6. Program to sort a NumPy array


import numpy as np

a = [Link]([[1, 4, 2],
[3, 6, 5],
[0, -1, 5]])

print("Sorted array:")
print([Link](a))

print("Row-wise sort:")
print([Link](a, axis=1))

print("Column-wise sort:")
print([Link](a, axis=0))

7. Convert a list into one-dimensional NumPy array


import numpy as np

original_list = [12.23, 13.32, 100, 36.32]

array = [Link](original_list)

print("Original List:", original_list)


print("NumPy Array:", array)

8. Create a 3×3 matrix with values from 2 to 10


import numpy as np

matrix = [Link](2, 11).reshape(3, 3)

print(matrix)

9. Program to reverse a NumPy array


import numpy as np

arr = [Link]([1, 2, 3, 4, 5])

print("Original array:", arr)


print("Reversed array:", arr[::-1])

10. Append values to the end of an array


import numpy as np

arr = [Link]([1, 2, 3])


values = [4, 5, 6]

new_arr = [Link](arr, values)

print("Original array:", arr)


print("Appended array:", new_arr)

11. Find common values between two arrays


import numpy as np
a1 = [Link]([1, 2, 3, 4, 5])
a2 = [Link]([3, 4, 5, 6, 7])

common = np.intersect1d(a1, a2)

print("Common values:", common)

12. Get unique elements of an array


import numpy as np

arr = [Link]([1, 2, 2, 3, 4, 4, 5])

print("Unique elements:", [Link](arr))

13. Set difference between two arrays


import numpy as np

a1 = [Link]([1, 2, 3, 4, 5])
a2 = [Link]([3, 4, 5, 6, 7])
diff = np.setdiff1d(a1, a2)

print("Set difference:", diff)

14. Union of two arrays


import numpy as np

a1 = [Link]([10, 20, 40, 60, 80])


a2 = [Link]([10, 30, 40, 50, 70])

union = np.union1d(a1, a2)

print("Union:", union)

15. Generate 5 random integers between 10 and 50


import numpy as np

random_numbers = [Link](10, 51, 5)


print(random_numbers)

🔹 PANDAS PROGRAMS

16. Create a Pandas Series from a list


import pandas as pd

s = [Link]([10, 20, 30, 40])

print(s)

17. Access elements of Series using index


import pandas as pd

s = [Link]([10, 20, 30], index=['a', 'b', 'c'])

print(s['a'])
print(s['c'])

18. Create DataFrame from dictionary


import pandas as pd

data = {
'Name': ['Amit', 'Ravi', 'Neha'],
'Marks': [85, 90, 88]
}

df = [Link](data)

print(df)

19. Compare elements of two Series


import pandas as pd

s1 = [Link]([2, 4, 6, 8, 10])
s2 = [Link]([1, 3, 5, 7, 10])

print(s1 == s2)

20. Sort a Pandas Series


import pandas as pd

s = [Link]([5, 2, 9, 1])

print(s.sort_values())

🔹 MATPLOTLIB PROGRAMS

21. Line plot


import [Link] as plt

x = [1, 2, 3, 4]
y = [10, 20, 25, 30]

[Link](x, y)
[Link]("X-axis")
[Link]("Y-axis")
[Link]("Line Plot")
[Link]()
22. Bar plot
import [Link] as plt

names = ['A', 'B', 'C']


marks = [80, 90, 85]

[Link](names, marks)
[Link]("Bar Plot")
[Link]()

23. Scatter plot


import [Link] as plt

x = [1, 2, 3, 4]
y = [10, 15, 20, 25]

[Link](x, y)
[Link]("Scatter Plot")
[Link]()
24. Histogram
import [Link] as plt

data = [10, 20, 20, 30, 40, 40, 40]

[Link](data)
[Link]("Histogram")
[Link]()

🔹 TKINTER PROGRAMS

25. Simple Tkinter window with Label


from tkinter import *

root = Tk()
[Link]("Tkinter Example")

label = Label(root, text="Hello Tkinter")


[Link]()
[Link]()

26. Tkinter Button


from tkinter import *

root = Tk()

def click():
print("Button clicked")

btn = Button(root, text="Click Me", command=click)


[Link]()

[Link]()

27. Tkinter Entry widget


from tkinter import *

root = Tk()
entry = Entry(root)
[Link]()

[Link]()

You might also like