繁体声/熊猫合并多种熊猫数据的方式是什么?ATM我用循环来做,但感觉不对:
我有三个带有信用运行时的数据,它们都有一个interest、liquidation和date字段。学分有不同的运行时(例如,不同的行)。
这是一个信用的样本。
amount annuity date int. int. % liq. liq. % special_payment
0 50,000.00 135.42 2016-09-01 52.08 1.25 83.33 2.00 0
1 49,916.67 135.42 2016-10-01 52.00 1.25 83.42 2.00 0
2 49,833.25 135.42 2016-11-01 51.91 1.25 83.51 2.00 0
3 49,749.74 135.42 2016-12-01 51.82 1.25 83.59 2.00 0
4 49,666.15 135.42 2017-01-01 51.74 1.25 83.68 2.00 0我要计算所有学分的总燃耗率。
这就是:
[interest + liquidation of credit 1] +
[interest + liquidation of credit 2] +
[interest + liquidation of credit 3]如果信贷不能在给定日期上运行,则interest + liquidation应该为零。
我对熊猫很陌生,所以我希望能对如何解决这个问题有一些见解。
发布于 2016-03-18 11:53:41
我认为您可以使用concat,但是您需要添加axis=1。我认为您需要使用keys参数,以便能够区分名称相同的列和不同的学分。
import pandas as pd
import numpy as np
df1 = pd.DataFrame(np.random.rand(4,4),columns=['a','b','c','d'])
df2 = pd.DataFrame(np.random.rand(4,4),columns=['a','b','c','d'])
df3 = pd.concat([df1,df2],axis=1,keys=['Credit1','Credit2'])若要从不同的列中添加数字,请使用。
burnrate = df3['Credit1','a']+df3['Credit2','a']https://stackoverflow.com/questions/36082749
复制相似问题