Python Libraries -2025 (1) Python Libraries -2025 (1) Python Libraries -2025 (1)
Python Libraries -2025 (1) Python Libraries -2025 (1) Python Libraries -2025 (1)
The Python programming language comes with a variety of built-in functions. Among these are
several common functions, including:
These built-in functions, however, are limited, and we can make use of modules to make more
sophisticated programs.
A module is a set of code or functions with the.py extension. A library is a collection of related
modules or packages. They are used by both programmers and developers. Libraries are used by
community members, developers and researchers.
Since math is a built-in module, your interpreter should complete the task with no feedback,
returning to the prompt. This means you don’t need to do anything to start using the math module.
Let’s run the import statement with a module that you may not have installed, like the 2D plotting
library matplotlib:
NumPy:
Numerical computing, array manipulation, and scientific computing.
Pandas:
Data manipulation and analysis, especially with DataFrames.
Matplotlib:
Data visualization, creating static, interactive, and animated visualizations.
Seaborn:
Statistical data visualization, building on Matplotlib for more visually appealing and informative
plots.
Scikit-learn: sklearn
Machine learning algorithms, providing tools for classification, regression, clustering, and more.
TensorFlow:
Deep learning framework, used for building and training neural networks.
SciPy:
Scientific computing, containing modules for optimization, integration, and signal processing.
PyTorch:
Another popular deep learning framework, known for its flexibility and dynamic computation graphs
Keras:
High-level API for building and training neural networks, often used as a front-end for TensorFlow
or Theano.
Basic data structures in pandas Pandas provides two types of classes for handling data:
1. Series: a one-dimensional labeled array holding data of any type such as integers, strings,
Python objects etc.
2. DataFrame: a two-dimensional data structure that holds data like a two-dimension array or a
table with rows and columns.
In [5]: 1 s
Out[5]: 0 1
1 3
2 5
3 0
4 6
5 8
dtype: int64
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_84444\2328450563.py in <module>
2 # nan is a blank cell, it is defined in numpy library
3
----> 4 s = pd.Series([1, 3, 5, np.nan, 6, 8])
In [7]: 1 # we need to import the numpy library to execute the code correctly
2 import numpy as np
In [9]: 1 s
Out[9]: 0 1.0
1 3.0
2 5.0
3 NaN
4 6.0
5 8.0
dtype: float64
In [12]: 1 df
Out[12]:
A B C D E F
Out[13]: (4, 6)
Out[14]: 4
Out[15]: 6
Out[16]: A float64
B datetime64[ns]
C float32
D int32
E category
F object
dtype: object
An object type is a user-defined composite datatype that encapsulates a data structure along with
the functions and procedures needed to manipulate the data. Data object will have memory
In [17]: 1 # after uploading the dataset onto your anaconda 3 folder (or the folder
2 # if the file you want to read is in .csv (comma seperated) then use pd.r
3 # Import an Excel file using the read_excel () function from the pandas l
4 # Set a column index while reading your data into memory.
5
6 data = pd.read_excel ('B Example 1 - Data Encoding.xlsx')
7 data
Out[17]:
S.N Country Hours Salary House
In [18]: 1 data.dtypes
In [20]: 1 # in bigger datasets, you may want to automatically check if data type 'o
2
3
4 column_type = column_name.dtype
5 if column_type == 'object':
6 print('The column contains string data')
7 else:
8 print('The column does not contain string data')
In [21]: 1 d = {
2 "A": 1.0,
3 "B": pd.Timestamp("20130102"),
4 "C": pd.Series(1, index=list(range(4)), dtype="float32"),
5 "D": np.array([3] * 4, dtype="int32"),
6 "E": pd.Categorical(["test", "train", "test", "train"]),
7 "F": "foo",
8 }
9 d
Out[22]:
A B C D E F
In [23]: 1 df.A
Out[23]: 0 1.0
1 1.0
2 1.0
3 1.0
Name: A, dtype: float64
In [24]: 1 df.B
Out[24]: 0 2013-01-02
1 2013-01-02
2 2013-01-02
3 2013-01-02
Name: B, dtype: datetime64[ns]
In [25]: 1 df [A]
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_84444\4086650841.py in <module>
----> 1 df [A]
In [26]: 1 df["A"]
Out[26]: 0 1.0
1 1.0
2 1.0
3 1.0
Name: A, dtype: float64
In [27]: 1 df.columns
In [28]: 1 df.index
Out[29]: 0 France
1 Spain
2 Germany
3 Spain
4 Germany
5 France
6 Spain
7 France
8 Germany
9 France
Name: Country, dtype: object
Out[30]: pandas.core.series.Series
Out[31]:
Country
0 France
1 Spain
2 Germany
3 Spain
4 Germany
5 France
6 Spain
7 France
8 Germany
9 France
Out[32]: pandas.core.frame.DataFrame