Python Convert Parquet to CSV

Problem πŸ’¬ Challenge: How to convert a Parquet file ‘my_file.parquet’ to a CSV file ‘my_file.csv’ in Python? In case you don’t know what a Parquet file is, here’s the definition: πŸ’‘ Info: Apache Parquet is an open-source, column-oriented data file format designed for efficient data storage and retrieval using data compression and encoding schemes to … Read more

Python Convert Markdown Table to CSV

Problem Given the following Markdown table stored in ‘my_file.md’: 🐍 Python Challenge: How to convert the Markdown table to a CSV file ‘my_file.csv’? Solution To convert a Markdown table .md file to a CSV file in Python, first read the Markdown table file by using the f.readlines() method on the opened file object f, by … Read more

Python – How to Convert KML to CSV?

What is KML? ℹ️ Definition: The Keyhole Markup Language (KML) is a file format for displaying geographic data in Google Earth or other so-called “Earth Browsers”. Similarly to XML, KML uses a tag-based structure with nested elements and attributes. How to Convert KML to CSV in Python? You can convert a .kml to a .csv … Read more

Python Convert GeoJSON to CSV

What is GeoJSON? πŸ’‘ GeoJSON is an RFC standardized data format to encode geographic data structures such as Point, LineString, Polygon, MultiPoint, MultiLineString, and MultiPolygon. GeoJSON is based on the JavaScript Object Notation (JSON). Example GeoJSON to CSV Say, you have the following GeoJSON snippet: You want to convert it to the following CSV format: … Read more

Python Convert Fixed Width File to CSV

What is a Fixed-Width File? πŸ’‘ Definition: A fixed-width text file contains data that is structured in rows and columns. Each row contains one data entry consisting of multiple values (one value per column). Each column has a fixed width, i.e., the same number of characters, restricting the maximum data size per column. Example of … Read more

How to Append a New Row to a CSV File in Python?

Python Append Row to CSV To append a row (=dictionary) to an existing CSV, open the file object in append mode using open(‘my_file.csv’, ‘a’, newline=”). Then create a csv.DictWriter() to append a dict row using DictWriter.writerow(my_dict). Given the following file ‘my_file.csv’: You can append a row (dict) to the CSV file via this code snippet: … Read more

How to Convert a Python Dict to CSV with Header?

To convert a Python dictionary to a CSV file with header, call the csv.DictWriter(fileobject, fieldnames) method. Use the resulting writer object’s writer.writeheader() method without argument to write the header. This writes the list of column names passed as fieldnames, e.g., the dictionary keys obtained via dict.keys(). After writing the header, you can then call the … Read more