My Coding >
Programming language >
Python libraries and packages >
Python Panda (Page: 1)
Go to Page:
Pandas install and upgrade
To work with Panda, it is necessary to have pandas library to be installed. Also together with pandas, you need to have numpy library. Pandas is abstraction on top of NumPy. This abstraction will make simple and powerful tool for manipulation of NymPy arrays
To install panda, you can use pip or conda commands:pip install pandas or conda install pandas
Some method and functions in Panda are version specific, therefore you always need to know, what version you have
If you think that you would like to install the latest version, then it is possible to do with pip install --upgrade pandas command-line
In all further codes we will assume, that all necessary libraries already imported. Also, if in some code we are using some variables or data structures without initialization, then we assume, that these variables were initialized in previous bits of code.
Pandas series is a one dimensional data structure.
Create Panda object from the list
The easiest way is to convert Python list into Panda Series
Access to element in pandas Series
It is possible to access elements of pandas Series via few different techniques
Access via index
Use index or slices like in traditional lists. It is always necessary to remember, that few elements are return back as a series. To convert them to list, use function list()
Access via list of indexes
It is possible to use list of indexes to access to the data in Series
Access via list of boolean
List of boolean can be used as a way to access data in series.
So, once again, it is possible to use Panda Series as a usual list, but the type can be different. It is possible to use metod tolist() to make type conversion. To access to element via index - use the index value in quotes
Index manipulations for Series
It is possible to create custom index for pandas series. It is important to remember, that index is not unique!
Initialization with dictionary
Panda structure can be initialized with dictionary. Key will be used as an Index
Extracting Index from Series
To exatract series index from the ata structure, use method index.
Name for the Series
Pandas series is a complex object, and this object have property name. It is possible to set it up and use it
To check which elements of two series is in common, you can use method isin(). The result will be boolean mask in series format. It is possible to use this mask to extract the data itself. It is possible to use ~ as an opposite operation
Operations with every element of Series
Combination of map() and lambda functions can allow to perform some operations over all elements in series. In following example we will make a squared elements
Element vice operations between series
It is possible to do some basic mathematical operations between elements of two series. Fro example add() for addition, mul() for multiplication etc. See dir(ps.Series) for the full list of methods. Please note, that after applying some of these methods, the type of Series can change! If some elements are not defined – you will have NaN value
Add or remove elements to Series
Append one series to another
It is possible to append one series to another, but oyu need to watch what till happen with indexes. Compare two examples with preserving indexes (default) and with generating new index
Removing elements from Series
It is possible to remove element by it’s index labelled with methoddrop(). This method do not change original series, but return new series
Other useful Series methods
Here I will give you few very useful Series methods without examples.
Last 10 artitles
9 popular artitles
|© 2020 MyCoding.uk -My blog about coding and further learning. This blog was writen with pure Perl and front-end output was performed with TemplateToolkit.