Posts

Showing posts with the label Reading Files

Featured Post

8 Ways to Optimize AWS Glue Jobs in a Nutshell

Image
  Improving the performance of AWS Glue jobs involves several strategies that target different aspects of the ETL (Extract, Transform, Load) process. Here are some key practices. 1. Optimize Job Scripts Partitioning : Ensure your data is properly partitioned. Partitioning divides your data into manageable chunks, allowing parallel processing and reducing the amount of data scanned. Filtering : Apply pushdown predicates to filter data early in the ETL process, reducing the amount of data processed downstream. Compression : Use compressed file formats (e.g., Parquet, ORC) for your data sources and sinks. These formats not only reduce storage costs but also improve I/O performance. Optimize Transformations : Minimize the number of transformations and actions in your script. Combine transformations where possible and use DataFrame APIs which are optimized for performance. 2. Use Appropriate Data Formats Parquet and ORC : These columnar formats are efficient for storage and querying, signif

3 Best Methods to Read Files in Python

Image
Python supports three specific methods to read files- read, readline, readlines. All these you use on files. Each has its unique purpose. Below are the best examples. 3 Methods to read file read readline readlines Method-1: read It reads records from file in sequence. Here, file.txt is sample file with single row. file.txt abcdefghijk file_object.read(2) ==> you will get 'ab' file_object.read(4)  ===> you will get 'cdef' Here, the multiple read methods read the data in sequence. The read(x) method will read only the number of characters that mentioned in the read method. Again, if you give multiple read methods then it will read in sequence. Method-2: readline It reads the file line by line. Here, file.txt is a file with single row. file.txt abcdefghijk f ile_object.readline() ==> you will get ' abcdefghijk ' Here, it reads the file line by line. Method-3: readlines It reads all the records at a time. Here, file.txt is a file with two rows. file.txt ab