Python unit 5
Python unit 5
Key Concepts:
1. Module: A single file containing Python code (functions, classes, variables, etc.)
with a .py extension.
2. Package: A directory containing multiple modules and an __init__.py file, which
makes it a package. The __init__.py file can be empty or execute initialization code
for the package.
2. module1.py:
3. module2.py:
Numpy: For numerical computations and operations on large arrays and matrices.
Installing Packages
Use pip, the Python package installer, to install packages from the Python Package
Index (PyPI).
Installation
Use color names (e.g., 'blue'), hex codes (e.g., '#FF5733'), or RGB tuples (e.g., (0.1, 0.2,
0.5)).
Markers:
Types include '.' (point), 'o' (circle), 's' (square), '^' (triangle), etc.
Functions for linear algebra operations such as dot products, matrix multiplication,
and eigenvalue decomposition.
Array Manipulation:
Series: A one-dimensional labeled array that can hold any data type.
DataFrame: A two-dimensional labeled data structure with columns of potentially different data
types.
Multi Atoms Plus
Creating Data Structures
# Creating a Series
s = pd.Series([1, 2, 3, 4, 5], name='numbers')
print(s)
# Creating a DataFrame
df = pd.DataFrame({
'A': [1, 2, 3],
'B': ['a', 'b', 'c'],
'C': [4.5, 5.5, 6.5]
})
print(df) Multi Atoms Plus
Data Manipulation:
Indexing and Selection: Accessing and manipulating data using labels and
integer-based indexing.
1. Indexing and Selection using Labels (loc): Accessing data using labels.
Handling Missing Data: Functions for detecting, filling, and dropping missing values.
Reading/Writing Data: Functions for reading from and writing to various file formats including CSV, Excel
1. Reading CSV Files: Using pd.read_csv() to read data from a CSV file.
2. Reading Excel Files: Using pd.read_excel() to read data from an Excel file.
Python offers several libraries to create GUIs, with Tkinter being the most commonly
used due to its simplicity and integration with Python's standard library. Other popular
GUI frameworks include PyQt, Kivy, and wxPython.
1. Button: A Button widget is used to display a clickable button that can trigger a
function or event when clicked.
● tk.Label(root, text="This is a label"): Creates a label with the text "This is a label".
● label.pack(): Adds the label to the window.
entry2 = tk.Entry(root)
entry2.pack()
result = tk.DoubleVar()
result_label = tk.Label(root, textvariable=result)
result_label.pack()
Multi Atoms Plus
1. Import Tkinter Module:
2. Define Functions:
This function retrieves the values from entry1 and entry2, adds
them, and sets the result in the result variable.
This creates the main window of the application and sets its title to "Simple Calculator".
Creates the second entry widget for user input and adds it to the window.
This creates a label that displays the result of the calculation. The label's text is bound to the result variable.
This starts the Tkinter event loop, which waits for user interactions and updates the GUI accordingly.
1. PyCharm: Developed by JetBrains, PyCharm is a powerful and widely-used IDE for Python. It
comes in two versions: Community (free) and Professional (paid).
● Intelligent Code Editor: Code completion, real-time error checking, and quick fixes.
● Debugging and Testing: Integrated debugger and test runner.
● Version Control: Supports Git, SVN and more.
● Web Development: Supports Django, Flask, and other web frameworks.
3. Spyder: An open-source IDE specifically designed for scientific computing and data analysis,
often used with Anaconda distribution.
3. Spyder: An open-source IDE specifically designed for scientific computing and data analysis,
often used with Anaconda distribution.