Which system variable is utilized to read the CSV and text files?

103    Asked by DelbertRauch in QA Testing , Asked on Jan 19, 2024

I am currently developing a script for reading CSV and text files. However, I am confused about which variable should I use for the specification of the delimiters used in the files, to ensure accurate parsing of the data. 

Answered by Charles Parr

 In the context of RPA, if you are working with CSV and text files and want to specify the delimiter, then you can use the system variable for specifications of the delimiters in tools or programming languages. In many programming languages, the “delimiter” or “step” parameters are generally used in specifying the delimiters while reading CSV and even text files. For example, in the context of Python programming language, the “pandas” library can be used for this particular objective. In this, you can use the “sep” parameter for the specification of the delimiters when using functions like “pd.read_csv”


Import pandas as pd
# Reading CSV file with a comma as the delimiter
Df_csv = pd.read_csv(‘your_file.csv’, sep=’,’)
# Reading text files with a specific delimiter (e.g., tab)
Df_text = pd.read_csv(‘your_text_file.txt’, sep=’ ’)

In this above example the “sep” refers to the CSV file being separated by the comma and the “sep= ” refers to the text file being separated by the tab. You can adjust the “sep” parameters based on your requirements.



Your Answer

Interviews

Parent Categories