Use-case description: Have a csv file which has two rows and five columns. The csv file contains the data of the user where owner column has just first name, followed by language which includes last name, email column with language(English) and empty header with value email id. Key highlighter of the use case is – the column owner should contain the first name & the last name, rest goes as per the below screenshot given from the csv file. End Result expected: Need to to shift the values of row #2 each by (-1)cell which should be aligned with the header values of the CSV file. Trying the same using the Python code But NO luck. Finding still deeper to dive into it & any guidance on this will be highly appreciated!!
This will shift the second row to the left in a CSV file with python, you can change it to shift other rows too
import csv with open("yourfile.csv") as csv_file: csv_reader = csv.reader(csv_file) with open("newfile.csv", "w", newline='') as new_csv_file: csv_writer = csv.writer(new_csv_file) i = 0 for row in csv_reader: if i == 1: row.pop(0) csv_writer.writerow(row) i += 1