简体   繁体   English

将列表(从mysql数据库获取)转换为数据帧需要花费大量时间

[英]Conversion of list(fetched from mysql database) to dataframe takes lot of time

I am trying to fetch a data frame from the mysql database. 我正在尝试从mysql数据库中获取数据帧。

my_db=src_mysql(dbname='****',
                host='****'
                ,port=****,user='****',password='****')

From this database(which shows as list of 2 in global environment) I want to extract a table. 我想从该数据库(在全局环境中显示为2的列表)中提取一个表。

w = src_tbls(my_db)[1]

But the above command return me a list. 但是上面的命令给我返回了一个列表。 I actually needed dataframe. 我实际上需要数据框。 Now to convert this list to dataframe is taking a lot of time. 现在将此列表转换为数据帧需要花费大量时间。

Can anyone suggest me a way to directly extract a dataframe from the database and reduce the total execution time of code. 谁能建议我一种直接从数据库中提取数据框并减少代码总执行时间的方法。

I'm not experienced with src_mysql() , but you might try the RODBC package. 我对src_mysql()没有经验,但是您可以尝试使用RODBC包。

This should give you a dataframe of your table and it might be faster given that your SQL statement isn't slow: 这应该为您提供表的数据框,并且鉴于您的SQL语句并不慢,它可能会更快:

library(RODBC)
channel <- odbcConnect("your dsn as character string", 
                       uid="****", # Username         
                       pwd="****",     
                       believeNRows=FALSE)
w <- sqlQuery(channel, "SELECT * FROM YOUR_TABLE")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM