Python or R: To read CSV files & read/write to Excel

Hi

I am new to both Python & R. I am not sure which to use for the following project:

  1. In an excel file, I have a list of the paths of CSV files.

  2. Starting from Row 1 in the Excel, I want to
    a. open the CSV file,
    b. use Regex expression to find some values in the CSV file,
    c. evaluate the values,
    d. output the result into the Excel file.

  3. Then move to Row 2 and repeat the above. The above steps are repeated until the last used row in the Excel file.

What are the pros & cons of using R or Python for the above? Eg, for Regex expression is it better to use Python or R

Thank you in advance!

I would instead read the entire Excel file and then filter for values matching the regular expression. Both R and Python have satisfactory tools (and regex support) for this task. It's more about what language you're comfortable coding in.

1 Like

Hi,

Thank you for reply. But it seems you are not reading my earlier post carefully.

I need to look for values in CSV files using REGEX expression.

For Excel files, I only need to
1 read a cell in every row for the path to open the CSV files
2 write the results of the values found in the CSV files.

Can R loop through each row of the Excel file and do the above? Thank you

Apologies, I misread your post. But the general approach I've suggested still holds. You should read the Excel file in its entirety first. Then loop over the CSV file paths to read the contents into a single data frame (I'm assuming that all CSVs have the same structure). In R, this can be done by using lapply() or purrr::map(). Similar tools also exist in Python.

After importing the CSVs, you can filter for the values you want using regular expressions. For the final step, you'll have to join the Excel data frame to the result and then export it.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.