python合并两个数据框_连接/合并数据框和编辑列名 - Python / Pandas(Concatenating/Merging Data Frames and Editing column n...

I have built a DataFrame out of a Python dictionary, with the following command:

population=pd.DataFrame(population.items(),columns=['Date','population']).set_index('Date').sort_index(ascending=True)

That gave me the following frame population:

population

Date

2015-08 69

2015-09 65

2015-10 65

2015-11 66

2015-12 71

Out of that DataFrame I created another one with its moving average, using the following command:

population_movav=pd.rolling_mean(population,10)

That gave me the following frame population_movav:

population

Date

2015-08 68.0

2015-09 69.9

2015-10 71.6

2015-11 71.1

2015-12 71.2

I want to combine them so they get like this:

population population_movav

Date

2015-08 69 68.0

2015-09 65 69.9

2015-10 65 71.6

2015-11 66 71.1

2015-12 71 71.2

Synthesizing, I need to concatenate them and change the column name of the variable population_movav. Tried the pd.concat but for some reason it is not working out right.

Can someone shine some light on it?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值