logo
down
shadow

How to extract a percentage column from a periodic column and the sum of the column?


How to extract a percentage column from a periodic column and the sum of the column?

Content Index :

How to extract a percentage column from a periodic column and the sum of the column?
Tag : python , By : jaredsmiller
Date : November 27 2020, 09:01 AM

should help you out Why the complication of another groupby? If all you want is to divide the column by the group sum, you can simply do:
train['PercentSales'] = train.groupby('Store')['Sales'].transform(lambda x: x/x.sum())
train['StoreTotalSales'] = train.groupby('Store'['Sales'].transform('sum')
train['PercentSales'] = train['Sales']/train['StoreTotalSales']

Comments
No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

use awk to calculate percentage of column 1 derived from column 2 and add it to column 3


Tag : awk , By : Andrew L.
Date : March 29 2020, 07:55 AM
should help you out I have a file consisting out of 2 columns, both contain only whole numbers. I want awk to add a third column which shows the percentage of column 1, derived from column 2. , Another awk
awk '$3=100*$1/$2' file
awk '$3=100*$1/$2' file > tmp && mv tmp file
awk '$2>0{$3=100*$1/$2}1' file > tmp && mv tmp file
awk '$2>0&&$3=100*$1/$2' file > tmp && mv tmp file

Extract a value in column A given the maximum value in column B within each group (column C) in an R dataframe?


Tag : r , By : brij
Date : March 29 2020, 07:55 AM
Any of those help My question is related to Extract the maximum value within each group in a dataframe. , Here is a base R and a data.table solution:
df <- structure(list(Group = c("A", "A", "B", "B", "B", "C", "D", "D"
), Value = c(12L, 10L, 3L, 5L, 6L, 1L, 3L, 4L), Year = c(1933L, 
2010L, 1935L, 1978L, 2011L, 1954L, 1933L, 1978L)), .Names = c("Group", 
"Value", "Year"), row.names = c(NA, -8L), class = "data.frame")

# Base R - use aggregate to get max Value per group, then merge with df
merge(df, aggregate(Value ~ Group, df, max), by.all = c("Group", "Value"))[
  , c("Group", "Year")]

#   Group Year
# 1     A 1933
# 2     B 2011
# 3     C 1954
# 4     D 1978

# data.table solution
library(data.table)
dt <- data.table(df)
dt[, .SD[which.max(Value), .(Year)], by = Group]

#    Group Year
# 1:     A 1933
# 2:     B 2011
# 3:     C 1954
# 4:     D 1978

Extract values for a column from another column based on another column in data frame R


Tag : r , By : Lauren Kirschner
Date : March 29 2020, 07:55 AM
hope this fix your issue If you don't want to have to hard code all of the column names you can use something like this.
comp.cols <- colnames(df)[grepl("_comp", colnames(df)) == TRUE]
non.comp.cols <- sub("_comp", "", comp.cols)

df[df[,"reg"] == "a", comp.cols] <- df[df[,"reg"] == "a", non.comp.cols]

how to extract column name and column value, by column number of all record from access query and / or table


Tag : development , By : Robin Buitenhuis
Date : December 22 2020, 01:30 PM
I wish this helpful for you I am trying to create vba code to generate kml data from access data , got the solution... here's my final code...
'define input box for target table
Dim Message, Title, Default, MyValue
Message = "Enter table/query name"  ' Set prompt.
Title = "kmlwriter"    ' Set title.
Default = "tablequeryname"    ' Set default.
MyValue = inputbox(Message, Title, Default)
'/inputbox

'define writing object for export
Dim fso As Object
Set fso = CreateObject("Scripting.FileSystemObject")

'define recordset for target table fetch and looping
Dim rs As DAO.Recordset
Set rs = CurrentDb.OpenRecordset("SELECT * FROM [" & MyValue & "]")

'define counter and output
Dim Fileout As Object
Dim i As Integer

'set output directory, replace 'peta' with something for sub directory of your currentdatabase
Set Fileout = fso.CreateTextFile(CurrentProject.Path & "\peta\" & MyValue & ".kml", True, True)

'standard header for kml
Fileout.write "<?xml version=""1.0"" encoding=""UTF-8""?><kml><Document><!-- Begin Style Definitions -->"


If Not (rs.EOF And rs.BOF) Then
    rs.MoveFirst 'Unnecessary in this case, but still a good habit

    Do Until rs.EOF = True

        'output name and coordinates, I place those 3 in order, latitude, longitude, point name
        Fileout.write vbNewLine & "<Placemark>"
        Fileout.write "<Point><altitudeMode>clampToGround</altitudeMode><extrude>0</extrude>"
        'rs(0) = latitude, rs(1) = longitude
        Fileout.write "<coordinates>" & rs(1) & "," & rs(0) & ",0" & "</coordinates></Point>"
        'rs(2) = point name
        Fileout.write vbNewLine & "<name>" & rs(2) & "</name><description><![CDATA["

        'output description for points
        For i = 3 To rs.Fields.Count - 1
             Fileout.write "<br><b>" & rs(i).Name & "</b> =" & rs(i)
        Next i
        Fileout.write "]]></description></Placemark>"

        'Move to the next record. Don't ever forget to do this.
        rs.MoveNext
    Loop
Else
    MsgBox "There are no records in the recordset."
End If

'standard kml footer
Fileout.write vbNewLine & "</Document></kml>"

Fileout.Close

'open save directory in mazimized windows
Shell "C:\WINDOWS\explorer.exe """ & CurrentProject.Path & "\peta", vbMaximizedFocus

How to compare one column value available or not in another column dataframe and extract another column of second datafr


Tag : python , By : user167963
Date : March 29 2020, 07:55 AM
Related Posts Related QUESTIONS :
  • Display image of 2D Sinewaves in 3D
  • how to prevent a for loop from overwriting a dictionary?
  • How To Fix: RuntimeError: size mismatch in pyTorch
  • Concatenating two Pandas DataFrames while maintaining index order
  • Why does this not run into an infinite loop?
  • Python Multithreading no current event loop
  • Element Tree - Seaching for specific element value without looping
  • Ignore Nulls in pandas map dictionary
  • How do I get scrap data from web pages using beautifulsoup in python
  • Variable used, golobal or local?
  • I have a regex statement to pull all numbers out of a text file, but it only finds 77 out of the 81 numbers in the file
  • How do I create a dataframe of jobs and companies that includes hyperlinks?
  • Detect if user has clicked the 'maximized' button
  • Does flask_login automatically set the "next" argument?
  • Indents in python 3
  • How to create a pool of threads
  • Pandas giving IndexError on one dataframe but not on another similar dataframe
  • Django Rest Framework - Testing client.login doesn't login user, ret anonymous user
  • Running dag without dag file in airflow
  • Filling across a specified dimension of a numpy array
  • Python populating dataframe in pandas from text files
  • How to interpolate a single ("non-piecewise") cubic spline from a set of data points?
  • Divide 2 integers (leetcode 29) - recursion issue
  • Can someone explain why do I get this output in Python?
  • How do I scrape pdf and html from search results without obvious url
  • Is there a way to automatically make a "collage" of plots with matplotlib?
  • How to combine multiple rows in pandas with shared column values
  • How do I get LOAD_CLASSDEREF instruction after dis.dis?
  • Django - How to add items to Bootstrap dropdown?
  • Linear Regression - Does the below implementation of ridge regression finding coefficient term using gradient method is
  • How to drop all rows in pandas dataframe with negative values?
  • Most Efficient Way to Find Closest Date Between 2 Dataframes
  • Execution error when Passing arguments to a python script using os.system. The script takes sys.argv arguments
  • Looping through a function
  • Create a plot for each unique ID
  • a thread python with 'while' got another thread never start
  • Solution from SciPy solve_ivp contains oscillations for a system of first-order ODEs
  • trigger python events driven by selenium controlled browser
  • Passing line-edits to a contextmanager to set validators
  • Python: globals().items() iterations try to change a dict
  • Is it possible to specify starting values for each parameter (instead of bounds) for scipy's differential evolution?
  • why datetime.now() and constructed datetime using all fields(like year,month...) of now has big timedelta?
  • MySQL multiple table UPDATE query using sqlalchemy core?
  • find if a semantic version is superset of of another version python
  • Type checking against dynamically created objects
  • Struggling with simple reverse function
  • Is there a function for finding the midpoint of n points on sklearn.neighbors.NearestNeighbors?
  • How to set max number of tweets to fetch
  • PYTHON 3.7.4 NOT USING SQLITE 3.29.0
  • How to replace Nan value with zeros in a numpy array?
  • How to speed up calculating variance among sparse matrix
  • cupy code is not fast enough compared with numpy
  • How to count frequency of select values in Python pandas dataframe
  • Scrape Span Text from Google
  • Python watchdog, watch a directory and rename file on event.modification
  • Filtering rows in DataFrame with dependent conditions
  • How to check if a character is a not a part of number or URL in string?
  • Compare corresponding elements of a list
  • Python misinterprets 3 character string as UTF-8 continuation byte
  • Merge two columns in Pandas
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com