如何将 pandas 列除以标量? [英] How do you divide pandas columns by a scalar?

查看:61
本文介绍了如何将 pandas 列除以标量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在熊猫数据框中有一个来自excel的文件.我有很多列和行,我想用标量(2.45)除所有列和行值(NaN除外).这就是我所拥有的:

I have a file from excel in a pandas dataframe. I have many columns and rows and I want to divide all column and row values (except NaN) by a scalar(2.45). This is what i have:

df = pd.read_excel('Ozflux.dailyLE.xlsx', sheetname='Sheet1', skiprows=0, index_col=2, na_values=[-9999])
ET = df.iloc[4: , 3: ]/2.45
print (ET)

它没有给我一个错误,但是这些值在ET中没有划分.有人有解决办法吗?

It doesn't give me an error but the values are not divided in ET. Anyone has solution?

推荐答案

如果整个DataFrame是数字的,则可以一次将所有值(甚至是NaN)除以2.45

If the whole DataFrame is numerical you can divide all the values (even the NaN's) by 2.45 at once

df= df/2.45
print(df)

请注意,我必须将DataFrame替换为df =才能使其保持粘性.

Notice I had to replace the DataFrame with df = to make it stick.

这篇关于如何将 pandas 列除以标量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆