You can open a CSV file in Python using the csv
module. To split the third column into multiple 25-row columns, you can use string and list manipulation techniques. Here's an example code snippet:
main.py1002 chars34 lines
This code defines a function process_csv
that takes a file path as input and performs the required modifications on the CSV file. It uses the chunks
generator function to split the third column into 25-row columns. Then, it inserts these new columns into the rows of the CSV file. Finally, it saves the modifications using the same file path.
The code then iterates over all the files in a folder (specified by folder_path
) using the os.listdir
function. It checks if each file has a ".csv" extension and passes its path to the process_csv
function to process the file.
Make sure to replace '/path/to/folder/'
with the actual path to the folder containing the CSV files in your system.
gistlibby LogSnag