Pandas DataFrame 到 Hive 表
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23817958/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Pandas DataFrame to Hive Table
提问by user3476463
I'm new to Python and Hive.
我是 Python 和 Hive 的新手。
I was hoping I might get some advice.
我希望我能得到一些建议。
Does anyone have any tips on how to turn a python pandas dataframe into a hive table?
有没有人有任何关于如何将 python pandas 数据框转换为 hive 表的提示?
回答by Jose Antonio Martin H
Your script should run inside a machine where hive can load data using the "load local data in path" method.
您的脚本应该在一台机器内运行,其中 hive 可以使用“在路径中加载本地数据”方法加载数据。
Query pandas data frame to create a list of column name datatype
Compose a valid HQL (DDL) create table statement using python string operations (basically concatenations)
Issue a create table statement in Hive.
Write the pandas dataframe as cvs separated by "\t" turning headers off and index off (check paramerets of to_csv() )
查询 pandas 数据框以创建列名数据类型列表
使用 python 字符串操作(基本上是串联)编写一个有效的 HQL (DDL) 创建表语句
在 Hive 中发出 create table 语句。
将 Pandas 数据帧写为 cvs,以“\t”分隔,关闭标题并关闭索引(检查 to_csv() 的参数)
5.- From your python script call a system console running hive -e:
5.- 从你的 python 脚本调用一个运行 hive -e 的系统控制台:
Use: for instance:
p = subprocess.Popen( ['hive', '-e', str_command_list], stdout = subprocess.PIPE,
stderr = subprocess.PIPE )
out, err = p.communicate()
This will call hive console and execute for instance, load data local inpath, inserting your csv data into the created table.
这将调用 hive 控制台并执行,例如,加载数据本地 inpath,将您的 csv 数据插入到创建的表中。
Then you are happy.
那你就开心了。

