logo
down
shadow

How can I sum values in column based on the value in another column?


How can I sum values in column based on the value in another column?

By : user3848043
Date : October 26 2020, 11:52 AM
hope this fix your issue I have a text file which is:
code :


Share : facebook icon twitter icon
Python Data Frame: Create New Column Based on Values in a String Column and a Float Column

Python Data Frame: Create New Column Based on Values in a String Column and a Float Column


By : Elias
Date : March 29 2020, 07:55 AM
hope this fix your issue You need add new condition with &. Also faster is use numpy.where:
code :
mask = (df_HA_noHA_act["Allocation Type"] == 'Predicted') & 
       (df_HA_noHA_act['Activities_Counter'] >= 10)
df_HA_noHA_act['Flag'] = np.where(mask, 'Flag', '')
df_HA_noHA_act = pd.DataFrame({'Activities_Counter':[10,2,6,15,11,18],
                              'Allocation Type':['Historical','Historical','Predicted', 
                                                  'Predicted','Predicted','Historical']})
print (df_HA_noHA_act)
   Activities_Counter Allocation Type
0                  10      Historical
1                   2      Historical
2                   6       Predicted
3                  15       Predicted
4                  11       Predicted
5                  18      Historical

mask = (df_HA_noHA_act["Allocation Type"] == 'Predicted') & 
       (df_HA_noHA_act['Activities_Counter'] >= 10)
df_HA_noHA_act['Flag'] = np.where(mask, 'Flag', '')
print (df_HA_noHA_act)
   Activities_Counter Allocation Type  Flag
0                  10      Historical      
1                   2      Historical      
2                   6       Predicted      
3                  15       Predicted  Flag
4                  11       Predicted  Flag
5                  18      Historical      
Flag = []
for i, row in df_HA_noHA_act.iterrows():
    if (row['Activities_Counter'] >= 10) and (row["Allocation Type"] == 'Predicted'):
        Flag.append('Flag')
    else:
        Flag.append('')
df_HA_noHA_act['Flag'] = Flag
print (df_HA_noHA_act)
   Activities_Counter Allocation Type  Flag
0                  10      Historical      
1                   2      Historical      
2                   6       Predicted      
3                  15       Predicted  Flag
4                  11       Predicted  Flag
5                  18      Historical    
df_HA_noHA_act = pd.DataFrame({'Activities_Counter':[10,2,6,15,11,18],
                              'Allocation Type':['Historical','Historical','Predicted', 
                                                  'Predicted','Predicted','Historical']})
print (df_HA_noHA_act)
#[6000 rows x 2 columns]
df_HA_noHA_act = pd.concat([df_HA_noHA_act]*1000).reset_index(drop=True)

In [187]: %%timeit
     ...: df_HA_noHA_act['Flag1'] = np.where((df_HA_noHA_act["Allocation Type"] == 'Predicted') & (df_HA_noHA_act['Activities_Counter'] >= 10), 'Flag', '')
     ...: 
100 loops, best of 3: 1.89 ms per loop

In [188]: %%timeit
     ...: Flag = []
     ...: for i, row in df_HA_noHA_act.iterrows():
     ...:     if (row['Activities_Counter'] >= 10) and (row["Allocation Type"] == 'Predicted'):
     ...:         Flag.append('Flag')
     ...:     else:
     ...:         Flag.append('')
     ...: df_HA_noHA_act['Flag'] = Flag
     ...: 
     ...: 
1 loop, best of 3: 381 ms per loop  
Excel function to Auto-Populate value in Column C based on the combination of values in column A and Column B

Excel function to Auto-Populate value in Column C based on the combination of values in column A and Column B


By : rdr
Date : March 29 2020, 07:55 AM
I wish this helpful for you If your sheet is set-up like this:
code :
=INDEX(C2:C10,INDEX(MATCH(1,(A2:A10=E2)*(B2:B10=F2),0),0))
how to conditionally create new column based on the values of a column in one dataframe and the column header names of a

how to conditionally create new column based on the values of a column in one dataframe and the column header names of a


By : minmin
Date : March 29 2020, 07:55 AM
hope this fix your issue I have a dataframe df1 which has a column named averageDate that contains dates, in the format of %Y-%m. , Something like this?
code :
require(tidyverse);
left_join(
    df1,
    df2 %>%
        gather(averageDate, Value, 2:ncol(df2)) %>%
        rename(zipcode = RegionName) %>%
        mutate(zipcode = as.character(zipcode)))
## A tibble: 4 x 3
#  zipcode averageDate   Value
#  <chr>   <chr>         <dbl>
#1 10019   2017-08     1849990
#2 10027   2017-04      929000
#3 94117   NA               NA
#4 20009   2015-11      504000
MySQL update a column's values to equal the sum of another column's values based on date and another column's value

MySQL update a column's values to equal the sum of another column's values based on date and another column's value


By : user1961602
Date : March 29 2020, 07:55 AM
I wish this helpful for you You need SUM() aggregation with Group By on team and game_date:
code :
SELECT 
  team, 
  game_date, 
  SUM(minutes) AS team_minutes_played 
FROM 
  your_table_name 
GROUP BY 
  team, 
  game_date 
Create column based on another column value, based on assigning value to sets of string values from the input column

Create column based on another column value, based on assigning value to sets of string values from the input column


By : user2394379
Date : March 29 2020, 07:55 AM
help you fix your problem Use map:
code :
lookup = {'F-On' : 'On', 'S-On' : 'On', 'circ':'fooON', 'TH':'fooON', 'circInS':'fooON', 'R':'R', 'S':'S'}
df['grouped_status'] = df.status.map(lookup)
            datetime  dty       dtx   status grouped_status
2018-09-16  04:38:17  0.0  0.099854     F-On             On
2018-09-16  04:38:18  0.0  0.100098     F-On             On
2018-09-16  04:38:19  0.0  0.000000     S-On             On
2018-09-16  04:38:20  0.0  0.100098     F-On             On
2018-09-16  04:38:21  0.0  0.100098     circ          fooON
2018-09-16  04:38:22  0.0  0.100098  circInS          fooON
2018-09-16  04:38:21  0.0  0.100098       TH          fooON
2018-09-16  04:38:21  0.0  0.100098        R              R
2018-09-16  04:38:21  0.0  0.100098        S              S
Related Posts Related Posts :
  • org.apache.flink.client.program.ProgramInvocationException: Could not retrieve the execution result
  • Does iText 7 PdfReader support partial reading?
  • Gensim doc2vec file stream training worse performance
  • How to properly reuse karate-config.js and test-header.feature
  • Recording questions and answers in FHIR structures
  • Informatica Designer (9.6.1.) Autolink wildcard
  • creating index on nvarchar(max) column
  • Does terraform support math rounding?
  • Microsoft Graph API - Document library creation with navigation link
  • Find the voice task currently assigned to a specific worker
  • Isabelle 2017 -- getting started
  • Redux Remove one item from cart
  • .NET Core Upgrading
  • How to implement distributed lock around poller in Spring Integration using ZooKeeper
  • Plone 4x: Can I get the title of a folder for the page content
  • Passing Query String Param into Response AWS API Gateway
  • Drive Api V3 - How to name file being uploaded?
  • IBM Watson speech to text WebSocket authorization with IAM API key
  • Why does ABAP cut string to one character?
  • Hide Taskbar button in FMX on Windows
  • Limit on the size of Azure table property that can be indexed by search?
  • How to authenticate to influxdb when using k6
  • How to customize the NSIS installer screens for multiple languages
  • How do I do a Depth First Search Alphabetically?
  • Updating already installed sideloaded uwp application
  • Formula returning previous month in `mmmm` format, only returns January
  • Postman API Tests
  • STRIPS Planner Doesn't Compile
  • WebCrypto AES-CBC outputting 256bit instead of 128bits
  • "File format not recognized" when building Petalinux app
  • Long living service with coroutines
  • Define data at cell centers using VTK format
  • Systemverilog interfaces over hierarchical boundaries
  • AIOHTTP:TypeError: index() takes 0 positional arguments but 1 was given
  • ProxySql Master node not serve the traffic untill slave gets shunned
  • Visual Studio 2019 Preview Remote Debugger
  • Setting composer (airflow) bucket using gcloud CLI
  • Cannot refresh subform from other subform
  • Email alert when field meets certain condition
  • MemSql > workaround for SELECT ... FOR UPDATE
  • Declarative Pipeline - Use of when condition, how to do nested conditions anyOf/allOf/not
  • Stateful microservices default 443 port share issue on the azure service fabric cluster
  • TYPO3 imagemagick makes images oversaturated
  • Typo-tolerant text searching?
  • How do I extract the components of a tuple in DAML?
  • Gimp 2.8.22: Change Color & Keep Transparency
  • I tried with this code, but it won't work with Ionic 3
  • Karate-Cucumber Report - No report file was added
  • Autofac - how to register a type used as a constructor parameter that requires the resolving (constructor) type as a gen
  • Tkinter filedialog is stealing focus and not returning it without "Alt-tab" in Python 3.4.1
  • jmeter dashboard report includes transaction controller children
  • Visual Branching in SourceTree
  • Doctrine2 orderBy in Symfony4 UnitTest
  • Match table-record to main-report dataset in Jaspersoft Studio
  • Drupal 8 custom module getting page not found
  • Is it possible that a container instance isn't really a container?
  • Padding not being understood in the UpSampling2D layer of a sequential layer
  • What is the incentive for a participating node in a "Proof of Stake" consensus model of Blockchain?
  • Radial gradient on a node in cytoscape
  • How to create operators from list in Airflow?
  • shadow
    Privacy Policy - Terms - Contact Us © bighow.org