0

I have a .xlsx file with column ['Bulb1_Cmd']

I want to multiply every item in that column by 10, update the dataframe and save as a new .xlsx file.

My current code that multiplies each value by 10 is:


df=pd.read_excel("bulb_data.xlsx")
s=df['Bulb1_Cmd']
for i in s.loc[:]:
    if i>0:
       ss=s.loc[:]*10

This will make a dataframe with the desired values, but I cannot figure out how to update the original dataframe with the new values.

I have tried

s.append(ss)
df.to_excel("newFile.xlsx")

with no luck

  • 2
    Please don't loop. Do this `df['Bulb1_Cmd'] = df['Bulb1_Cmd'] * 10`: – David Erickson Oct 26 '20 at 20:20
  • 1
    `df['Bulb1_Cmd'] *= 10` – cs95 Oct 26 '20 at 20:21
  • https://stackoverflow.com/questions/33768122/python-pandas-dataframe-how-to-multiply-entire-column-with-a-scalar – noah Oct 26 '20 at 20:27
  • I need to use a loop for future data handling. If a value is y.... – Gumbynator Oct 26 '20 at 20:30
  • "I need to use a loop for future data handling. If a value is y." You don't *need* to use a loop for most things in pandas. This is a fundamental thing to understand. Instead use `.where()`, `.mask()` or `np.where()` to apply calculations conditionally. – David Erickson Oct 26 '20 at 20:51

0 Answers0