logo
down
shadow

dataframe values multiply by 2


dataframe values multiply by 2

Content Index :

dataframe values multiply by 2
Tag : python , By : Juice
Date : November 29 2020, 04:01 AM

I wish this helpful for you It seems the type of columns is of str/object type and hence it is appending rather then multiplying
Example
import pandas as pd
pd.DataFrame({'x':['0.1']})*2
0.10.1
pd.DataFrame({'x':[0.1]})*2
0.2
print(df.dtypes)
for col in ['4DS.AX','A2B.AX','A2M.AX','AAC.AX','ABC.AX','ABP.AX','ACW.AX','ADH.AX']:
    df[col] = df[col].astype('float')
df.iloc[0,:]*2.0

Comments
No Comments Right Now !

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

Share : facebook icon twitter icon

R multiply columns by values in second dataframe


Tag : r , By : jumpingmattflash
Date : March 29 2020, 07:55 AM
wish of those help I have two dataframes: df1 , Your data:
df1 <- read.table(
  text = 
    "plot   grass moss   rock    other     stuff  
    a      4      0     0       text      3
    b      2      2     0       text      4
    c      10     0     0       text      0
    d      3      1     0       text      9",
  header = TRUE
)

df2 <- read.table(
  text = 
    "Cover  value
    grass   5
    moss    2
    rock    3",
  header           = TRUE,
  stringsAsFactors = FALSE
)
df3 <- df1
for(i in seq_len(nrow(df2)))
{
  df3[, df2$Cover[i]] <- df2$value[i] * df1[, df2$Cover[i]]
}

How to multiply all hourly values in one pandas dataframe with yearly values in another dataframe?


Tag : python-2.7 , By : dexteryy
Date : March 29 2020, 07:55 AM
wish helps you You can try append to index of df1 df1.index.year, then change index of df2 to years and then use mul:
print df1
                     Value1  Value2
Date/Time                          
2010-01-03 00:00:00      60      10
2010-01-03 01:00:00      50      20
2010-01-03 02:00:00      52      30
2010-01-03 03:00:00      49      40
2013-12-31 23:00:00      77      50

print df2
            Value1  Value2
Date/Time                 
2010-12-31     1.5     0.9
2011-12-31     1.6     1.1
2012-12-31     1.7     2.3
2013-12-31     1.3     0.6

df1 = df1.set_index(df1.index.year, append=True)
df2.index = df2.index.year
print df1
                          Value1  Value2
Date/Time                               
2010-01-03 00:00:00 2010      60      10
2010-01-03 01:00:00 2010      50      20
2010-01-03 02:00:00 2010      52      30
2010-01-03 03:00:00 2010      49      40
2013-12-31 23:00:00 2013      77      50

print df2
      Value1  Value2
2010     1.5     0.9
2011     1.6     1.1
2012     1.7     2.3
2013     1.3     0.6

print df1.mul(df2, level=1).reset_index(drop=True, level=1)
                     Value1  Value2
Date/Time                          
2010-01-03 00:00:00    90.0       9
2010-01-03 01:00:00    75.0      18
2010-01-03 02:00:00    78.0      27
2010-01-03 03:00:00    73.5      36
2013-12-31 23:00:00   100.1      30

Multiply dataframe with values from other dataframe


Tag : python , By : Ronnie Carlin
Date : March 29 2020, 07:55 AM
wish of those help I have two dataframes , Use set_index and reindex to align df2 with df1 and then mul
In [1150]: df1.mul(df2.set_index(0).reindex(df1.index)[1], axis=0)
Out[1150]:
     d    e
a   10   20
b   60   80
c  150  180
a   70   80

Iterate over every row in pandas dataframe and multiply all row values by one of the row values in same dataframe


Tag : python , By : Anonymous
Date : March 29 2020, 07:55 AM
hope this fix your issue You can using str.contains , then assign the mul result back with .loc , also here since you need assign it back ,with filter will failed
s=df.columns.str.contains('Count')
df.loc[:,s]=df.loc[:,s].mul(df['Normalization Value'],0)
df
Out[238]: 
   Sample  Timepoint         ...          CountC Normalization Value
0       1          1         ...             5.0                 0.1
1       2          1         ...            20.0                 0.2
2       2          2         ...            20.0                 0.5
[3 rows x 8 columns]

Conditionally multiply values in a dataframe by another dataframe if above a certain threshold in R


Tag : r , By : Guyou
Date : March 29 2020, 07:55 AM
wish of those help We can get the indices where Pdist is greater than threshold and then multiply.
inds <- dataframe_1$Pdist > threshold
dataframe_1$Pdist[inds] <- dataframe_1$Pdist[inds] * dataframe_2$Pdist[inds]
Related Posts Related QUESTIONS :
  • 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
  • Side Effect error in Python in an online compiler
  • How to convert a navigation list with depth levels to a parent-child flat list?
  • Retrieving values from a paired key dictionary in Python
  • How to test the current text of a Tkinter text box widget before inserting new text after user clicks on a button?
  • computing the Cumulative Sum, where Sum can be reset by a condition
  • Where do you specify your API key when making a request with the Google API python library?
  • Pandas DataFrame, computing the Time Difference between one row and other row which satisfies a condition
  • Discord.py bot not reading other bot's messages
  • How do I write a Django query that finds words in a Postgres column?
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com