SQL
UNION 竖向拼接
参考 <https://www.w3school.com.cn/sql/sql_union.asp>
竖向拼接dataframe:
SQL UNION 和 UNION ALL 操作符
SQL UNION 语法
SELECT column_name(s) FROM table_name1
UNION
SELECT column_name(s) FROM table_name2
注释:默认地,UNION 操作符选取不同的值。如果允许重复的值,请使用 UNION ALL。
SQL UNION ALL 语法
SELECT column_name(s) FROM table_name1
UNION ALL
SELECT column_name(s) FROM table_name2
另外,UNION 结果集中的列名总是等于 UNION 中第一个 SELECT 语句中的列名。
select * from
(
select * from
table1 a
left join
select * from table2 b
on
a.col1=b.col2 )
Pandas
Python DataFrame 合并
https://www.jb51.net/article/138127.htm
横着合并,增加新的列
Eg. out = pd.concat([df_result_ofACA,df_result_ofACA2],axis=1)
在axis=0为纵向拼接,此时有
concat([df1,df2]) 等价于 df1.append(df2) |
在axis=1 时为横向拼接 ,此时有
concat([df1,df2],axis=1) 等价于 merge(df1,df2,left_index=True,right_index=True,how='outer')
|
Pandas创建空dataframe 用于拼接
https://blog.csdn.net/roamer314/article/details/80886075
#建空数据
results=pd.DataFrame(columns=(
'rankingid',
'officialpoiid',
))
#后面接上新数据df_next,和results有一样的列名
#可以通过循环,改变df_next
results=pd.concat([results,df_next],axis=0)
#保存
results.to_csv('./results_all_df_pd_route_AllInfo_final_detail.csv',index=True)
拼接:
https://blog.csdn.net/mr_hhh/article/details/79488445
https://pandas.pydata.org/pandas-docs/version/0.20/generated/pandas.concat.html
pandas的join、merge、concat
https://www.cnblogs.com/xk-bench/p/8379180.html
pyspark
pyspark合并/竖直拼接行、列
https://blog.csdn.net/yepeng2007fei/article/details/78645329
合并列:
df.withColumn(新列名,df[列名]) #将df中的列合并到df中
行合并:
df.union(df1) #将df与df1进行行合并,这时df与df1的列名要相同
join 横向拼接
eg: df1.join(df2, col1==col2, "left")