你好,我有一个数据框,我想添加两个新的字典了。我可以添加一个,但它会覆盖现有数据,不会添加另一个。我怎样才能解决这个问题
这就是我目前正在尝试的,它执行计算并将创建新文件,但它只创建一列,不包含任何现有数据。我怎样才能解决这个问题,这可能吗
谢谢
#Fill the data from excel
data = pd.read_excel('file.xlsx')
df = pd.DataFrame(data)
#Perform calculations
new_col_a = np.multiply(df['somecol'], x_rate)
new_col_b = np.subtract(new_col_a, df['somecol'])
#create the new columns
df['col_a'] = new_col_a
df['col_b] = new_col_b
#now create new excel file
df.to_excel('new.xlsx')
事实上我没有答案,因为某种原因这行
someDict=np.multiply(df['ColA',some_rate)现在抛出'type object not subscribtable'我没有做任何更改,所以我唯一能想到的是numpy升级了什么?奇怪
相关问题 更多 >
编程相关推荐