赞
踩
df_concat_resample = pd.concat([nr_in_27, nr_in_103], axis=1, ignore_index=False)
首先创建两个Series对象为例
首先要提醒的是,DataFrame对象的每一列都可以看做是一个Series对象
换句话说,DataFrame对象可以看做是多个Series对象拼接而成
concat()函数里面有两个常用的参数axis 和ignore_index, 默认值分别为axis=0, ignore_index=False, axis=0表示行拼接,axis=1表示列拼接
s1
和 s2
使用 pd.concat([s1, s2], axis=0, ignore_index=False)
,会发现这样会直接把s1和s2进行简单的行拼接————拼成一列pd.concat([s1, s2], axis=1, ignore_index=False)
,结果是把s1和s2中具有相同索引的值进行了拼接, 最后的结果变成了一个具有两列的DataFrame对象import numpy as np
import pandas as pd
from pandas import Series, DataFrame
# 下面两个方法都可以
# frame = DataFrame(np.arange(9).reshape(3,3), columns=list('abc'), index=['one', 'two', 'threee'])
frame = DataFrame(np.arange(9).reshape(3,3), columns=['a','b','c'], index=['one', 'two', 'threee'])
# print(frame)
series = frame['b']
# print(series)
frame和Series如下:
In[3]: frame
Out[3]:
a b c
one 0 1 2
two 3 4 5
threee 6 7 8
In[4]: series
Out[4]:
one 1
two 4
threee 7
Name: b, dtype: int32
下面是运算交互:
DataFrame.operate(Series, axis=0)
In[5]: frame.add(series, axis=0)
Out[5]:
a b c
one 1 2 3
two 7 8 9
threee 13 14 15
In[6]: frame.sub(series, axis=0)
Out[6]:
a b c
one -1 0 1
two -1 0 1
threee -1 0 1
In[7]: frame.mul(series, axis=0)
Out[7]:
a b c
one 0 1 2
two 12 16 20
threee 42 49 56
In[8]: frame.div(series, axis=0)
Out[8]:
a b c
one 0.000000 1.0 2.000000
two 0.750000 1.0 1.250000
threee 0.857143 1.0 1.142857
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。