Python Forum
Combine a number into integer column and preserv format as number
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Combine a number into integer column and preserv format as number
#1
Hi

I have a DataFrame 150.000 rows x 56 columns.
I need change value in column MVA and put number 1 first any value

Before
MVA
38.24
33.29
25.08
31.37
29.02

After
MVA
1.3824
1.3329
1.2508
1.3137
1.2902
At the end I need this column with type number (int or float), because a I'll use for calculations.

I try this
df['MVA'] = df['MVA'].apply(lambda x: x*100)
But how insert number 1 front values?
Reply
#2
You'll need to divide by 100 to move the decimal point and then add 1. This should do it.

df['MVA'] = df['MVA'].apply(lambda x: x / 100 + 1)
Reply
#3
Hi stullis

my god, this is beautiful.

Thank you so much
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to count total number of sheets in an excel workbook using polars sayyedkamran 0 630 Oct-27-2023, 09:54 PM
Last Post: sayyedkamran
  OR-Tools LP Limit Number of Elements in Solution idratherbecoding 0 743 May-14-2023, 11:02 PM
Last Post: idratherbecoding
  Cubic interpolation in Pandas raises ValueError: The number of derivatives at boundar JaneTan 2 2,447 Dec-10-2022, 04:28 AM
Last Post: JaneTan
  Add group number for duplicates atomxkai 2 1,094 Dec-08-2022, 06:08 AM
Last Post: atomxkai
  [machine learning] identifying a number 0-9 from a 28x28 picture, not working SheeppOSU 0 1,824 Apr-09-2021, 12:38 AM
Last Post: SheeppOSU
  How to copy a .csv worksheet into a .xlsx file without the number values turning into YoshikageKira 7 3,468 Mar-28-2020, 10:38 AM
Last Post: buran
  How to match number of features of training dataset to testing input anhnguyen 0 1,820 Feb-05-2020, 08:28 PM
Last Post: anhnguyen
  weird number output karlito 12 4,482 Dec-13-2019, 12:11 PM
Last Post: perfringo
  how to list/count the number of dictionaries paul18fr 2 1,946 Nov-18-2019, 09:50 PM
Last Post: paul18fr
  spread values of dataset equally over fixed number of bins moose_man 3 2,472 Oct-30-2019, 07:41 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

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