My Coding >
Programming language >
Python >
Python libraries and packages >
Python Panda
Python Panda (Page: 1)Go to Page:
Pandas install and upgradeTo 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 Pandas instalationTo 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
Pandas upgradeIf 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 seriesPandas series is a one dimensional data structure. Create Panda object from the listThe easiest way is to convert Python list into Panda Series
Access to element in pandas SeriesIt is possible to access elements of pandas Series via few different techniques Access via indexUse 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 indexesIt is possible to use list of indexes to access to the data in Series
Access via list of booleanList 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 SeriesIt is possible to create custom index for pandas series. It is important to remember, that index is not unique!
Initialization with dictionaryPanda structure can be initialized with dictionary. Key will be used as an Index
Extracting Index from SeriesTo exatract series index from the ata structure, use method index.
Name for the SeriesPandas series is a complex object, and this object have property name. It is possible to set it up and use it
Compare SeriesTo 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 SeriesCombination 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 seriesIt 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 SeriesAppend one series to anotherIt 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 SeriesIt 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 methodsHere I will give you few very useful Series methods without examples.
Go to Page: 1; 2; 3; 4; 5; 6; 7; 8;
|
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. |