day05:数据重构
*数据合并的三种方法
list_up = [text_left_up,text_right_up]
result_up = pd.concat(list_up,axis=1)
list_down=[text_left_down,text_right_down]
result_down = pd.concat(list_down,axis=1)
result = pd.concat([result_up,result_down])
resul_up = text_left_up.join(text_right_up)
result_down = text_left_down.join(text_right_down)
result = result_up.append(result_down)
result_up = pd.merge(text_left_up,text_right_up,left_index=True,right_index=True)
result_down = pd.merge(text_left_down,text_right_down,left_index=True,right_index=True)
result = resul_up.append(result_down)
思考:merge、join以及concat的方法的不同以及相同
1、当没有索引时:merge、join为按照一定条件合并
2、当有索引、并按照索引合并时,得到结果为两者混合到一起了,重新按照一定规则排序了。
3、当没有索引时、concat不管列名,直接加到一起,可以加到后面、也可以加到右边,axis=0为加到后面,axis=1为加到右边,左边的数据结构没有变,变的是右边数据结构。
4、当有索引、并按照索引合并时,得到结果两者混合到一起了。
详细可参考:http://www.elecfans.com/d/611543.html
*数据变为Series类型的数据
unit_result=text.stack().head(20)
思考:
1. 将数据编程series类型的作用和用法:
Series类型类似于Numpy的一维数组对象,可以将该类型看做是一组数据与数据相关的标签(索引)联合而构成(带有标签的一维数组对象)。
详细可参考:https://blog.csdn.net/haiqiang1995/article/details/94355657
2. stack()函数的作用:
对arrays里面的每个元素(可能是个列表,元组,或者是个numpy的数组)变成numpy的数组后,再对每个元素增加一维(至于维度加在哪里,是靠axis控制的),然后再把这些元素串起来。
详细可参考:https://www.jb51.cc/python/490516.html
本次的学习基于datawhale学习打卡小组: