【问题标题】:How to multiply one column to few other multiple column in Python DataFrame如何在 Python DataFrame 中将一列与其他几列相乘
【发布时间】:2015-12-15 07:31:47
【问题描述】:

我有一个包含 100 列的数据框,我想将一列 ('Count') 值乘以从 6 到 74 的列位置。请告诉我该怎么做。 我一直在努力

df = df.ix[0, 6:74].multiply(df["Count"], axis="index")
df = df[df.columns[6:74]]*df["Count"]

它们都不工作

Dataframe 的结果应该是 100 列,其中所有原始列的第 6 到 74 列在所有行中都有相乘的值。

【问题讨论】:

    标签: python dataframe multiplication


    【解决方案1】:

    您可以将列相乘。

    columns = df.columns[6:75]
    df[columns] *= df['Count']
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-04-07
      • 2021-12-31
      • 1970-01-01
      • 1970-01-01
      • 2016-02-19
      • 2023-03-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多