here are the colums in dataFrame
想要执行这些计算
active energy per mint = global_active_power*1000/60 - sub_metering_1 - sub_metering_2 - sub_metering_3
这是我写的代码,但不知道如何做到这一点。
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
# Importing the dataset
training_set = pd.read_csv('household_power_consumption.txt', delimiter = ';', low_memory=False)
consumed_energy_every_minute = training_set.Global_active_power * (100/60) - training_set.Sub_metering_1 - training_set.Sub_metering_2 - training_set.Sub_metering_2
然后想要将该值列添加到数据帧中。
发布于 2017-06-21 07:55:19
这样的东西就可以完成这项工作:
import pandas as pd
f=pd.DataFrame({'a':[1,2,3],'b':[4,5,6],'c':[7,8,9]})
f['k']=f.a*1000/60 - f.b - f.c
最初的f
看起来像
a b c
0 1 4 7
1 2 5 8
2 3 6 9
更新后的f
看起来像这样
a b c k
0 1 4 7 5.666667
1 2 5 8 20.333333
2 3 6 9 35.000000
https://stackoverflow.com/questions/44664581
复制相似问题