如何仅从CSV文件中获取指定的必需列并添加到Postgresql中的表中? [英] How do I take only specified required columns from CSV file and add into a table in postgresql?

查看:116
本文介绍了如何仅从CSV文件中获取指定的必需列并添加到Postgresql中的表中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑我有

*----*------*-----------*----------*----------*---------------*----------------*
| id | name | addressid | address1 | address2 | attendancekey | attendancedate |
*----*------*-----------*----------*----------*---------------*----------------*

CSV文件中的列,我只想要

columns in CSV file and I want only


  1. id ,姓名和要导入的学生表和

addressid,address1,address2 导入地址表和

出勤键和出勤日期导入到出勤数据库中的表。

attendancekey and attendancedate to be imported in attendance table in database.

使用什么查询将所需的列导入到表中?

What query to be used to import the required columns into the table?


数据库Postgresql版本-12

Database Postgresql Version - 12

Python版本-3.4.4

Python Version - 3.4.4

Psycopg2版本-2.7.5

Psycopg2 Version - 2.7.5


推荐答案

您可以使用 df.iterrows()在csv上进行迭代,对于每一行,只需插入所需的键即可。

You can iterate over the csv using df.iterrows() and for each row you can insert into the table just the key you need.

这篇关于如何仅从CSV文件中获取指定的必需列并添加到Postgresql中的表中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆