“Pivot -Tisch mit Numpy” Code-Antworten

Drehpunkt 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];
    }
}
Prabhu Kiran Konda

Pandas Pivot Table

>>> emp.pivot_table(index='dept', columns='gender',                     values='salary', aggfunc='mean').round(-3)
Uninterested Unicorn

Pivot -Tisch mit 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)
Elisabeth Engering

Ähnliche Antworten wie “Pivot -Tisch mit Numpy”

Fragen ähnlich wie “Pivot -Tisch mit Numpy”

Weitere verwandte Antworten zu “Pivot -Tisch mit Numpy” auf Python

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen