My Coding >
Programming language >
Python >
Python libraries and packages >
Python Panda
Python Panda (Page: 8)Go to Page:
DataFrame in Pandas can have more that one index column. In this case these DataFrames are called multi-index dataframes. In this short artile, I will show you how to create and use Multi-index DataFrame Creation MultiIndex DataFrameWe have table with Shape, Color, Count and Size information for some objects stored in CSV data. First of all, we will read CSV this dataset into a dataframe without any indexes.
At the second step, we will declare columns ‘Shape’ and ‘Color’ as index columns
Grouping by indexesGroup DataFrame by one indexIt is possible to group by any indexes and do some calculations within these groups. For example, lets group all objects by its ‘Shape’ and calculate mean values for the rest of parameters
It is possible to group by any indexes. For example let’s count how many data we have for different ‘Color’. It is important to remember, that count() give number of elements without NaN and size() give total number of elements, with NaN
Group DataFrame by two indexesIt is possible to group by few indexes. And also it is possible to specify an order of grouping. So let’s group by ‘Color’ and then by ‘Shape’ and then let’s calculate the average values in every group.
Use groupAfter grouping, it it is possible to call one group
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. |