Python Forum
change array column values without loop
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
change array column values without loop
#2
The answer depends on what container did you use to store the data. If you are working with numpy arrays,
you can do that as follows:

import numpy as np
x = np.array([0.16, 0, 0, 0.65, 0.17])
x[x < 0.5] *= 2
If your data is presented as a column of Pandas dataframe, you can do it by almost similar way:

# df Pandas data frame
df[df.iloc[:, <column number>]<0.5] *= 2
Reply


Messages In This Thread
RE: change array column values without loop - by scidam - May-05-2019, 07:46 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Get an average of the unique values of a column with group by condition and assign it klllmmm 0 314 Feb-17-2024, 05:53 PM
Last Post: klllmmm
  Converting column of values into muliple columns of counts highland44 0 271 Feb-01-2024, 12:48 AM
Last Post: highland44
  Loop over an an array of array Chendipeter 1 604 Nov-28-2023, 06:37 PM
Last Post: deanhystad
  Loop through values and compare edroche3rd 6 715 Oct-18-2023, 04:04 PM
Last Post: edroche3rd
  output values change akbarza 3 554 Oct-18-2023, 12:30 PM
Last Post: deanhystad
  Loop through json file and reset values [SOLVED] AlphaInc 2 2,184 Apr-06-2023, 11:15 AM
Last Post: AlphaInc
  Change a numpy array to a dataframe Led_Zeppelin 3 1,149 Jan-26-2023, 09:01 PM
Last Post: deanhystad
  PowerBI: Using Python Regex to look for values in column MarcusR44 1 996 Oct-14-2022, 01:03 PM
Last Post: ibreeden
  How to combine multiple column values into 1? cubangt 15 2,902 Aug-11-2022, 08:25 PM
Last Post: cubangt
  Creating a loop with dynamic variables instead of hardcoded values FugaziRocks 3 1,533 Jul-27-2022, 08:50 PM
Last Post: rob101

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020