将元组列表附加到数据框python panda

时间:2017-10-05 01:20:05

标签: python pandas

df=pd.DataFrame([["a1","a2","a3"],["b1","b2","b3"],["c1","c2","c3"]])

我想要的是什么:

df2 = pd.DataFrame(tlist, columns=['col1', 'col2', 'col3'])

我可以这样做:

#very big table#
sql2 = "Select col1,col2,col3 from bigT"
#very big table#
try:
  cursor.execute (sql2)
except cx_Oracle.DatabaseError:
  print ('Failed \n'+sql2)

#need to do it in chunk as not enough memory and blow up!
while True:
   tlist = cursor.fetchmany()
   print(type(tlist))
   print (len(tlist))
   if rows == []:
        break;
   #I cannot get this one to work
   df.append([tlist],ignore_index=True)
   #I cannot get this one to work

但是,元组列表是从某个数据库中提取的,所以我有一个循环,并一次拉取一个数据块,然后追加。

最好的办法是什么?

现在数据拉动最多可达10亿行,并且可以增长。

感谢。

  clickHandler(current) {
    this.props.dispatch({type: 'updateMenuFave', current: current });
  }

2 个答案:

答案 0 :(得分:1)

我找到了一个更简单的解决方案!

import pandas as pd
print(con.version)
query = """select * from all_tab_columns"""
df_ora = pd.read_sql(query, con=con)

答案 1 :(得分:0)

tabID