Python Forum
copy one column from csv file and paste into xls file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
copy one column from csv file and paste into xls file
I am a beginner in python. I ma working on csv file and xls file both.
how can i copy one column of csv fle and paste it into xls file in paste special mode.

To open csv file i got 2 options 1)by importing csv 2)by importing pandas
To open xls file i am importing xlrd.

i am not uderstanding how i can code to copy and paste using two different libraries.

looking for useful links or suggestions.please guide me.
Thanks in advance.

code :-

import xlrd
import pandas as pd
import openpyxl
import csv

# path of xls file
file_location = "C:/Users/Kanchan/Desktop/try.xls"
#path of csv file
file_location_p = "C:/Users/Kanchan/Desktop/NAVUpdate_31-Aug-2018.csv"

# working with xls file using xlrd

workbook = xlrd.open_workbook(file_location)
sheet = workbook.sheet_by_index(0)
value = sheet.cell_value(0,0)
data = pd.read_csv(file_location_p)
print(data.head() )
data1 = [[sheet.cell_value(r,c) for c in range (sheet.ncols)] for r in range (sheet.nrows)]
for col in range (sheet.ncols):
for col in range (sheet.ncols):

#using csv to work with csv file
rows = []
# reading csv file
with open(file_location_p, 'r') as csvfile:
# creating a csv reader object
csvreader = csv.reader(csvfile)

# extracting each data row one by one
for row in csvreader:

# copy xls file data using xlrd
rows =sheet.nrows
columns =sheet.ncols
listab = []
for i in range(1,rows+1):

for r in range(1,rows+1):
for c in range(1,2):


Possibly Related Threads…
Thread Author Replies Views Last Post
  Export dataframe to xlsx - Error "zipfile.BadZipFile: File is not a zip file" Baggio 10 35,474 Mar-12-2021, 01:02 PM
Last Post: buran
  Filter data based on a value from another dataframe column and create a file using lo pawanmtm 1 3,367 Jul-15-2020, 06:20 PM
Last Post: pawanmtm
  XLSX file with multiple sheets to josn file ovidius 2 1,500 Apr-05-2020, 09:22 AM
Last Post: ovidius
  How to print a column name in csv file Truman 1 3,404 Mar-31-2020, 03:34 AM
Last Post: Larz60+
  How to copy a .csv worksheet into a .xlsx file without the number values turning into YoshikageKira 7 2,139 Mar-28-2020, 10:38 AM
Last Post: buran
  [split] Converting excel file to txt file unexceptionalhobby 2 3,400 Oct-16-2019, 06:34 PM
Last Post: unexceptionalhobby
  Change column names from a file Nidhesh 2 2,287 Jul-08-2019, 06:00 AM
Last Post: Nidhesh
  Copy raw data in excel to another new excel file keerthiprashanth 5 2,739 Oct-20-2018, 10:13 AM
Last Post: volcano63
  Upload csv file as numbers (floating?) and extract element, row, and column bentaz 7 3,436 Mar-19-2018, 05:34 PM
Last Post: bentaz
  Converting excel file to txt file muhsin 3 20,321 Oct-13-2017, 07:52 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020