You can use the pandas
library in Python to read individual CSV files in a folder and split the second column into multiple 25-row columns. Here's an example code snippet to achieve this:
main.py797 chars26 lines
In this code snippet, we first set the folder_path
variable to the directory path where the CSV files are located.
Then, we initialize an empty dataframe called combined_df
to store the final result.
Next, we loop through each file in the folder using the os.listdir
function. If the file has the extension .csv
, we read it using pd.read_csv
and store the data in the df
dataframe.
We then split the second column of the df
dataframe into multiple columns, each with 25 rows, using a list comprehension and the iloc
method of pandas dataframe. Each split column is stored in the split_cols
list.
Finally, we use pd.concat
to concatenate the split columns horizontally (axis=1) and then concatenate the result to the combined_df
dataframe.
At the end of the loop, the combined_df
dataframe will contain the desired result, with the second column of each CSV file split into multiple 25-row columns.
Note: Don't forget to replace 'path_to_folder'
with the actual path to your folder containing the CSV files.
gistlibby LogSnag