Answers for "Pivot table with numpy"

1

Pivot in array

// https://leetcode.com/problems/find-minimum-in-rotated-sorted-array
// assuming Array has no duplicates
class Solution {
    public int findMin(int[] nums) {
        int start = 0;
        int end  = nums.length-1;
        
        while (start < end){
            int mid = start + (end-start)/2;
            if (nums[mid] > nums[end]) start = mid+1;
            if (nums[mid] < nums[end]) end = mid;
        }
        return nums[start];
    }
}
Posted by: Guest on January-17-2022
0

Pandas pivot table

>>> emp.pivot_table(index='dept', columns='gender',                     values='salary', aggfunc='mean').round(-3)
Posted by: Guest on August-09-2021
0

Pivot table with numpy

import numpy as np

# Get pivit table with statistic and fill missing values
df.pivot_table(values = "weekly_sales", index = "type", aggfunc = np.sum, fill_value = 0)

# Get pivit table with multiple statistics and fill missing values
df.pivot_table(values = "weekly_sales", index = "type", aggfunc = [np.sum, np.min, np.max], fill_value = 0)

# Get pivit table with multiple statistics and variables and fill missing values
df.pivot_table(values = "weekly_sales", index = "type", aggfunc = [np.sum, np.min, np.max], columns = "store", fill_value = 0)

# Get the sum of all rows and columns in pivot table
df.pivot_table(values = "weekly_sales", index = "type", aggfunc = [np.sum, np.min, np.max], columns = "store", fill_value = 0, margins = True)

# Display DataFrame
print(df)
Posted by: Guest on April-29-2022

Code answers related to "Pivot table with numpy"

Python Answers by Framework

Browse Popular Code Answers by Language