To read a CSV file in a folder and split the second column into multiple 25-row columns in Python, you can use the pandas library. Here's an example of how you can achieve this:
main.py687 chars25 lines
This code will iterate over all the CSV files in the specified folder, read them using pd.read_csv()
, and store the datasets in a list called data
. Then, it concatenates all the dataframes in data
into a single dataframe called merged_df
.
Next, the second column of merged_df
is split into multiple columns, with each column containing 25 rows. This is achieved by using a list comprehension and the iloc
function from pandas. Finally, the resulting split columns are concatenated along the column axis using pd.concat()
.
Note: Don't forget to import the necessary libraries (pandas
and os
) at the beginning of your code.
gistlibby LogSnag