By clicking “Accept All Cookies”, you agree to the storing of cookies on your device to enhance site navigation, analyze site usage, and assist in our marketing efforts. View our Privacy Policy for more information.
CSV files provide a simple and efficient way of storing and transferring data between different applications. In this article, we’ll provide a comprehensive guide to what CSV files are, their various uses, benefits, and limitations.
CSV files (“comma separated value files'', or “comma delimited files”) are one of the most common formats for spreadsheet programs. CSV files are plain text files where commas are used to delimit (separate) data. Because the CSV files provide a simple and standardized format that can be easily read and processed by most software applications, they’re widely used across multiple industries to exchange data.
In this article, we’ll provide a comprehensive guide to:
What CSV files are
Common CSV file use cases
CSVs compared with other common file formats (JSON and XML)
The main advantages of using CSV files
The limitations, drawbacks, and common problems with CSV files
What is a CSV file?
CSV files are plain text files where the values in each row are separated by commas, and each row is ended by a line break. The CSV file format is one of the most common formats for sending and storing tabular data.
What does CSV stand for?
"CSV" stands for "comma-separated values". In the CSV file format, commas are used to separate the values in different cells in a spreadsheet data format.
What is .csv?
The ".csv" file extension is used for files in the CSV (comma-separated values) format. While the .csv format has a defined structure, .csv files are often inconsistency formatted, leading to challenges with file parsing and CSV data import.
How is a CSV file structured?
CSV files are plain text files where the values in each row are separated by commas, and each row is ended by a line break.
The relatively simple structure of CSV data allows it to be human-readable, and viewable in many programs including text editors such as TextEdit or Notepad. CSV files often contain a header row at the top which specifies the titles of each column in the file.
Spreadsheet applications, such as Microsoft Excel, convert CSV files into a tabular format, with each row representing a record and each column representing a field.
CSV files end with the extension “.csv”, and the simple structure of CSV data makes it an efficient format for storing and transferring data between different applications.
CSV file delimiters
The CSV file format is one of several "delimited text file" formats. Aside from commas, other common delimiters used in CSV files include:
Semicolons (;)
Pipes (|)
Tabs ( )
Quotes (“, ‘)
For example, in the dataset "jane;doe;FL", the semicolon (;) separates the three data items jane, doe, and FL. If pipes were used as the delimiter instead, the dataset would read “jane|doe|FL”.
Understanding how to use delimiters seems fairly straightforward, but once you’re working with actual datasets, problems arise quickly. For example, how do you handle a comma in a value where commas are also being used as the delimiter for the file? One option would be to surround that value in double quotes, but what if the quote character is also being used inside that value? How about the situation where a newline is used to separate each record, but it’s also present inside of an entry?
Properly handling these complications are often dependent on the platform, so depending on where the CSV data was exported from, a different set of rules in order needs to be applied to properly interpret the dataset.
When are CSV files used?
Because CSV files are designed to be relatively simple, they’re frequently used across a wide range of industries to transfer complicated data between applications. With CSV files, it’s possible to export complicated data from one application to a CSV format, and then import that exported CSV data into another application where it can be used.
Another one of the most common CSV file use cases is for uploading a list of contacts into an application. This can be used to send marketing campaigns through an email delivery platform like SendGrid, or synching customer information into a CRM like Salesforce.
CSV file use cases span across various industries and professions, from business and finance to science and research. Some of the most common CSV use cases include:
Data Import and Export: One of the most common use cases for CSV files is data import and export. Given their simplicity and compatibility, CSV files are often used to transfer data between different types of software, applications, and databases. For instance, a user might export data from a MySQL database into a CSV file for use in an Excel spreadsheet or a Python data analysis tool like pandas.
Data Analysis: CSV files are a popular choice in data analysis due to their compatibility with various data analysis tools and languages, such as R, Python, and SQL. Analysts can easily manipulate and analyze data stored in CSV files, making them a common format for storing datasets.
Data Migration: When migrating data from one system to another, CSV files are often used due to their simplicity and compatibility. For example, when moving customer data from one Customer Relationship Management (CRM) system to another, the data might be exported to a CSV file and then imported into the new system.
Data Backup: CSV files can be used to create backups of data. Given their simplicity and plain text format, CSV files can be a good choice for creating readable, accessible backups of important data.
Reporting: CSV files are often used for generating reports, especially for data-heavy applications. These reports can then be easily opened, manipulated, and analyzed using spreadsheet software.
Machine Learning: In machine learning, CSV files are often used to store training datasets. These files can be easily loaded into machine learning libraries like scikit-learn in Python, where they can be used to train various types of models.
While CSV files have their limitations and potential security concerns, their simplicity, versatility, and wide acceptance make them a go-to choice for many data-related tasks.
Opening and editing CSV files
Opening CSV files with Excel
Microsoft Excel is the most widely used spreadsheet application for opening and editing CSV files, however tools like Numbers for Mac or Google Sheets are also common. In this section, we’ll focus on Excel.
To open a CSV file, simply double-click the file or open it from the Excel program. Once opened, you can edit any cell by clicking on it and modifying its contents directly in that cell or in the area called fx, which stands for “Excel Functions.”
If you want to create a new CSV file, open Microsoft Excel and save a new file as a CSV. You can then edit it and it will continue to save as a CSV whenever you click save. To get started, create the headings for your columns. For example, if you want to create a list of contact information for your team, create one column for first names, another for last names, another for phone numbers, and another for email addresses.
Finally, it’s worth noting that besides CSV files, there are other file formats that can be used for spreadsheets. When working in Google Sheets, for example, you can download the file in several different formats, including Microsoft Excel (.xlsx), OpenDocument format (.ods), PDF document (.pdf), Web page (.html), and tab-separated values (.tsv). Excel also offers numerous formatting options, including: Excel Workbook (.xlsx), Excel Macro-Enabled Workbook (.xlsm), Excel Binary Workbook (.xlsb), Excel 97-2003 Workbook (.xls), XML Data (.xml), and many more.
Reading CSV Files into Python using Pandas
Most programming languages have a CSV parsing library (e.g. here is Python’s, which is part of their standard library).
Pandas is a data manipulation and analysis library for Python, which can be helpful for performing complex transformations and analyses on CSV data. One of the drawbacks is it’s not performant on large datasets (e.g. multiple GB), so depending on the size of CSV data you’re working with it may not be an option. CSV data from Pandas can also be exported into many different formats.
CSV command line tools
For some use cases, command line tools like xsv and csvkit can be great options. xsv is able to function quickly even with large files of >1GB, and allows you to perform simple functions like sorting, reformatting, and fixing data. For more complex data transformations, csvkit has more built in features (e.g. allowing you to convert between CSV and other formats), but isn’t as performant as xsv for larger files.
Relational and hosted databases
Relational databases generally have built-in functions to import or export from CSVs, and can be a good choice for working with complex transformations on large datasets. For extremely large amounts of data (10+ GBs), hosted tools like Redshift and BigQuery, which are columnar databases, allow you to not have to worry about setting up a database server.
Handling special characters in CSV files
In CSV files, a special character is any character that is not alphabetic or numeric.
While there are no limits of what characters can be used in a CSV file, the way the file is encoded will determine the restrictions. UTF-8 is generally the recommended encoding for CSV files because it supports almost every possible character. When opening a CSV in a program other than a text editor (such as Excel), symbols like "??????" and "Êæ§ÖÂ" will be displayed if a character is unsupported. To fix this issue, import CSV files into Excel using the Text Import Wizard and select the proper encoding as the file origin.
Converting CSV files
There are several methods of converting CSV files. You can convert CSV files into other file formats like .xlsx with utilities like CloudConvert, or just by opening the file in Excel and saving with a different file extension. There are also a large number of libraries for converting spreadsheet files into formats like JSON or XML, like csvtojson.
Advantages of CSV files
The underlying structure of the CSV format often makes them a more viable choice compared to heavier formats such as XML and more complex databases. These structural benefits are particularly impactful in areas involving data transfer, data analysis, data manipulation, and data management.
Broad compatibility
One of the most prominent advantages of the CSV format is its broad compatibility. They’re designed to be universally accessible, with most software applications being able to easily read and process CSV files. This compatibility spans a wide range of databases, various programming languages, and data analysis and visualization tools. All modern spreadsheet applications, include Microsoft Office, Google Sheets, Airtable, and OpenOffice support CSV files.
At their core, CSV files are designed to be relatively clear-cut and easy to use. They have standardized and intuitive formatting where files always consist of rows that represent data records, and columns that represent their respective attributes. This underlying structure doesn’t require any complex software to open and edit (they can even be manipulated in simple text editors like Notepad or TextEdit), and allows for CSV data to be easily understood by non-technical users. The ability to be used across nearly every platform makes CSV files an incredibly popular choice when in the area of data exchange between different systems. They’re also the most used file type when users need to import or export data across different platforms or within an application.
Efficiency
Efficiency is another key benefit that CSV files offer. Their simple, lightweight structure that lacks any formatting or styling that would otherwise increase the file size or slow down their performance. Their compact nature also allows them to be easily compressed and emailed.
CSV data can be generated, stored, and transferred easily, making them ideal for scenarios where data needs to be exchanged or analyzed quickly. This characteristic is also particularly beneficial when dealing with large volumes of data that wouldn’t be performant when put into other file formats. Additionally, CSV files are compatible with version control systems, supporting detailed tracking of changes over time.
{{blog-content-cta}}
Limitations of CSV files and common problems
User error and improperly formatted CSV data
While CSV files can provide a simple way of storing and transferring data, they are unstandardized and prone to user-error. Although the CSV format has been used for decades, there’s no standardized format enforced across applications. In 2005, the RFC 4180 was released, but most platforms don’t follow it (e.g. Microsoft Excel explicitly does not). Users can often accidentally enter incorrect or incomplete data, such as duplicate headers, missing values, incorrect data in fields (such as emails missing the “@” symbol), or unsupported characters (causing encoding issues).
As the name suggests, CSV data is typically separated by commas. Because of this, most standard libraries expect a comma as the delimiter, and require you to manually overwrite the configuration if the separator is not a comma (e.g. the col_sep setting in Ruby). It’s also possible to write code that attempts to detect the delimiter used in a file, however, encountering uncommon cell delimiters can cause major issues and require manual review before the data can be properly loaded.
Since they can cause a number of downstream data management issues, it’s critical to ensure that the data imported from CSV files is accurate, complete, and consistent with the intended format. Applications typically need to receive CSV files in a particular structure (and with correctly entered data) to avoid unexpected behavior or invalid analyses.
For example, if contacts are uploaded into a CRM through a CSV file that has missing fields, email campaigns like the one below may be sent out if steps aren’t taken to clean up the file first:
Because of the negative impacts from improperly formatted data, systems will often block imports that aren’t don’t match the exact specifications they expect (whether it’s that all header rows must match, there are not duplicate emails, every first and last name are in proper case, etc.), preventing users from progressing to the core value of a product until they’re able to reformat the file appropriately.
Data transfer challenges
Since exporting csv files is a common feature in most web applications, the CSV format is a common method of file transfer. For complex datasets or ones that must be imported in a specific format, investing time building a CSV import flow that instructs users through cleaning and formatting their CSV data before importing the file can also help – especially when specific, complex formatting of the file is necessary. For applications where a user is importing CSV files, if there are strict validation requirements, a lack of guidance during the import process can result in an influx of support ticket requests. Because of the endless possibilities on the types of formatting and data entry errors, resolving import errors often requires manual debugging from technical and non-technical team members, and causes customers to drop off during onboarding processes due to added frustrations.
High memory usage and performance at scale
Most 3rd party tools that handle importing CSVs don’t support large file sizes (e.g. 10M rows), and are not performant at sizes above 1M rows. This is because most point solutions load, validate, and visualize spreadsheet data all at once on the browser rather than a more performant design (such as an in-memory Rust data service that allows for real-time processing, regardless of file size). As CSV data scales to millions of rows, additional features such as caching are required to ensure speed is maintained while visualizing and validating data.
Data transformation is often challenging with large CSV files. When working with programs like Excel or Google Sheets, there are also typically size limits on CSV files. You can only import or export up to 1,048,576 rows or 16,384 columns in Excel, and 5,000,000 cells (with a maximum of 256 columns per sheet) in Google Sheets.
CSV file security concerns
While the CSV file format offers numerous advantages, it also has potential security risks to be mindful of. One of the most notable vulnerabilities is CSV Injections (also known as Formula Injections). CSV Injection is a security vulnerability that occurs when a CSV file containing malicious input is interpreted by a spreadsheet program (such as Microsoft Excel or Google Sheets). Specifically, these attacks can be executed when the CSV data includes entries that are interpreted as formulas by these spreadsheet programs.
For example, an attacker can insert a string like "=cmd|' /C calc'!A0" into a CSV file. When this file is opened in a spreadsheet program, it interprets the string as a formula, and in this case, it would execute a command (in this case, launching the calculator application). More harmful commands could potentially compromise the system or network.
Below are some other security concerns associated with CSV files:
Data Integrity: CSV files do not support encryption or password protection. This means that they can be opened by anyone with access to the file, potentially compromising the integrity and confidentiality of the data.
Data Leakage: Since CSV files are plain text, they can be easily read if intercepted during transmission or if stored without adequate protection. This could lead to data leakage, especially if the data is sensitive or confidential.
Lack of Data Validation: CSV files do not have built-in mechanisms for data validation. This means they could contain erroneous or malicious data, which could lead to inaccurate analyses or security vulnerabilities.
To mitigate these security risks, it's important to validate and sanitize data before it's written into a CSV file, treat all CSV files from untrusted sources as potentially dangerous, and consider the use of more secure file formats when handling sensitive data.
Comparing CSV, JSON, and XML
CSV, JSON, and XML are three of the most common formats for storing and transferring data. Each of these formats has its own unique properties that make them well suited for different types of use cases.
CSVs vs. JSON
The primary difference between CSV and JSON is the way data is stored. The CSV format stores data in a tabular format, with rows representing records and columns representing fields. JSON, on the other hand, uses a hierarchical structure of nested key-value pairs. JSON is not typically used with spreadsheet applications like Microsoft Office, OpenOffice, Airtable, or Google Sheets.
CSV vs. XML
Like CSV, XML stores data in a tabular format with rows representing records and columns representing fields. However, XML also uses tags to define elements and attributes to define their properties. This also means XML generally provides more structure and flexibility when compared to CSV. XML allows you to define custom tags and attributes, which makes it well-suited for document-based data.
Choosing the right file format
Here are some general guidelines when deciding what file format to use:
CSV: For tabular data where a simple format that's easy to read and write is needed.
JSON: When building a web application or API where a lightweight format that's easy to parse and generate in JavaScript is needed.
XML: For document-based data like invoices, reports, or other business documents (CSV can also be used in this case depending on the structure of the data).
Ultimately, the choice of format depends on the specific needs of your application and the data you're working with.
Building a CSV importer
While building a basic importer is straightforward, there are numerous advanced features to consider when launching a CSV importer for production use cases. Spreadsheet import can be an awful experience in so many products due to data tools lacking the advanced features necessary to handle messy data. When users are faced with messages like “error on line 53”, they can end up never getting started with the product.
If you're planning to build a CSV import feature yourself, here are our recommended best practices. However, integrating high quality spreadsheet import capabilities into a product can become a never-ending sink for engineering and support resources that many teams don’t have the resources to launch. Due to the constant edge cases that can occur from user error, teams have to constantly add validations and continue QA testing over 6 months after the initial feature launch.
Instead of spending months writing data validations and handing CSV parsing edge cases, integrating CSV import tools such as OneSchema can allow you to focus your development resources on your core product.Companies like Scale AI and Ramp are using OneSchema to make it fast and easy to launch delightful spreadsheet import experiences, from embeddable CSV import, to importing CSVs from an SFTP folder on a recurring basis. OneSchema intelligently corrects messy data so you can improve your customer activation rates and launch better onboarding experiences than your competitors.
CSV files (“comma separated value files'', or “comma delimited files”) are one of the most common formats for spreadsheet programs. CSV files are plain text files where commas are used to delimit (separate) data. Because the CSV files provide a simple and standardized format that can be easily read and processed by most software applications, they’re widely used across multiple industries to exchange data.
In this article, we’ll provide a comprehensive guide to:
What CSV files are
Common CSV file use cases
CSVs compared with other common file formats (JSON and XML)
The main advantages of using CSV files
The limitations, drawbacks, and common problems with CSV files
What is a CSV file?
CSV files are plain text files where the values in each row are separated by commas, and each row is ended by a line break. The CSV file format is one of the most common formats for sending and storing tabular data.
What does CSV stand for?
"CSV" stands for "comma-separated values". In the CSV file format, commas are used to separate the values in different cells in a spreadsheet data format.
What is .csv?
The ".csv" file extension is used for files in the CSV (comma-separated values) format. While the .csv format has a defined structure, .csv files are often inconsistency formatted, leading to challenges with file parsing and CSV data import.
How is a CSV file structured?
CSV files are plain text files where the values in each row are separated by commas, and each row is ended by a line break.
The relatively simple structure of CSV data allows it to be human-readable, and viewable in many programs including text editors such as TextEdit or Notepad. CSV files often contain a header row at the top which specifies the titles of each column in the file.
Spreadsheet applications, such as Microsoft Excel, convert CSV files into a tabular format, with each row representing a record and each column representing a field.
CSV files end with the extension “.csv”, and the simple structure of CSV data makes it an efficient format for storing and transferring data between different applications.
CSV file delimiters
The CSV file format is one of several "delimited text file" formats. Aside from commas, other common delimiters used in CSV files include:
Semicolons (;)
Pipes (|)
Tabs ( )
Quotes (“, ‘)
For example, in the dataset "jane;doe;FL", the semicolon (;) separates the three data items jane, doe, and FL. If pipes were used as the delimiter instead, the dataset would read “jane|doe|FL”.
Understanding how to use delimiters seems fairly straightforward, but once you’re working with actual datasets, problems arise quickly. For example, how do you handle a comma in a value where commas are also being used as the delimiter for the file? One option would be to surround that value in double quotes, but what if the quote character is also being used inside that value? How about the situation where a newline is used to separate each record, but it’s also present inside of an entry?
Properly handling these complications are often dependent on the platform, so depending on where the CSV data was exported from, a different set of rules in order needs to be applied to properly interpret the dataset.
When are CSV files used?
Because CSV files are designed to be relatively simple, they’re frequently used across a wide range of industries to transfer complicated data between applications. With CSV files, it’s possible to export complicated data from one application to a CSV format, and then import that exported CSV data into another application where it can be used.
Another one of the most common CSV file use cases is for uploading a list of contacts into an application. This can be used to send marketing campaigns through an email delivery platform like SendGrid, or synching customer information into a CRM like Salesforce.
CSV file use cases span across various industries and professions, from business and finance to science and research. Some of the most common CSV use cases include:
Data Import and Export: One of the most common use cases for CSV files is data import and export. Given their simplicity and compatibility, CSV files are often used to transfer data between different types of software, applications, and databases. For instance, a user might export data from a MySQL database into a CSV file for use in an Excel spreadsheet or a Python data analysis tool like pandas.
Data Analysis: CSV files are a popular choice in data analysis due to their compatibility with various data analysis tools and languages, such as R, Python, and SQL. Analysts can easily manipulate and analyze data stored in CSV files, making them a common format for storing datasets.
Data Migration: When migrating data from one system to another, CSV files are often used due to their simplicity and compatibility. For example, when moving customer data from one Customer Relationship Management (CRM) system to another, the data might be exported to a CSV file and then imported into the new system.
Data Backup: CSV files can be used to create backups of data. Given their simplicity and plain text format, CSV files can be a good choice for creating readable, accessible backups of important data.
Reporting: CSV files are often used for generating reports, especially for data-heavy applications. These reports can then be easily opened, manipulated, and analyzed using spreadsheet software.
Machine Learning: In machine learning, CSV files are often used to store training datasets. These files can be easily loaded into machine learning libraries like scikit-learn in Python, where they can be used to train various types of models.
While CSV files have their limitations and potential security concerns, their simplicity, versatility, and wide acceptance make them a go-to choice for many data-related tasks.
Opening and editing CSV files
Opening CSV files with Excel
Microsoft Excel is the most widely used spreadsheet application for opening and editing CSV files, however tools like Numbers for Mac or Google Sheets are also common. In this section, we’ll focus on Excel.
To open a CSV file, simply double-click the file or open it from the Excel program. Once opened, you can edit any cell by clicking on it and modifying its contents directly in that cell or in the area called fx, which stands for “Excel Functions.”
If you want to create a new CSV file, open Microsoft Excel and save a new file as a CSV. You can then edit it and it will continue to save as a CSV whenever you click save. To get started, create the headings for your columns. For example, if you want to create a list of contact information for your team, create one column for first names, another for last names, another for phone numbers, and another for email addresses.
Finally, it’s worth noting that besides CSV files, there are other file formats that can be used for spreadsheets. When working in Google Sheets, for example, you can download the file in several different formats, including Microsoft Excel (.xlsx), OpenDocument format (.ods), PDF document (.pdf), Web page (.html), and tab-separated values (.tsv). Excel also offers numerous formatting options, including: Excel Workbook (.xlsx), Excel Macro-Enabled Workbook (.xlsm), Excel Binary Workbook (.xlsb), Excel 97-2003 Workbook (.xls), XML Data (.xml), and many more.
Reading CSV Files into Python using Pandas
Most programming languages have a CSV parsing library (e.g. here is Python’s, which is part of their standard library).
Pandas is a data manipulation and analysis library for Python, which can be helpful for performing complex transformations and analyses on CSV data. One of the drawbacks is it’s not performant on large datasets (e.g. multiple GB), so depending on the size of CSV data you’re working with it may not be an option. CSV data from Pandas can also be exported into many different formats.
CSV command line tools
For some use cases, command line tools like xsv and csvkit can be great options. xsv is able to function quickly even with large files of >1GB, and allows you to perform simple functions like sorting, reformatting, and fixing data. For more complex data transformations, csvkit has more built in features (e.g. allowing you to convert between CSV and other formats), but isn’t as performant as xsv for larger files.
Relational and hosted databases
Relational databases generally have built-in functions to import or export from CSVs, and can be a good choice for working with complex transformations on large datasets. For extremely large amounts of data (10+ GBs), hosted tools like Redshift and BigQuery, which are columnar databases, allow you to not have to worry about setting up a database server.
Handling special characters in CSV files
In CSV files, a special character is any character that is not alphabetic or numeric.
While there are no limits of what characters can be used in a CSV file, the way the file is encoded will determine the restrictions. UTF-8 is generally the recommended encoding for CSV files because it supports almost every possible character. When opening a CSV in a program other than a text editor (such as Excel), symbols like "??????" and "Êæ§ÖÂ" will be displayed if a character is unsupported. To fix this issue, import CSV files into Excel using the Text Import Wizard and select the proper encoding as the file origin.
Converting CSV files
There are several methods of converting CSV files. You can convert CSV files into other file formats like .xlsx with utilities like CloudConvert, or just by opening the file in Excel and saving with a different file extension. There are also a large number of libraries for converting spreadsheet files into formats like JSON or XML, like csvtojson.
Advantages of CSV files
The underlying structure of the CSV format often makes them a more viable choice compared to heavier formats such as XML and more complex databases. These structural benefits are particularly impactful in areas involving data transfer, data analysis, data manipulation, and data management.
Broad compatibility
One of the most prominent advantages of the CSV format is its broad compatibility. They’re designed to be universally accessible, with most software applications being able to easily read and process CSV files. This compatibility spans a wide range of databases, various programming languages, and data analysis and visualization tools. All modern spreadsheet applications, include Microsoft Office, Google Sheets, Airtable, and OpenOffice support CSV files.
At their core, CSV files are designed to be relatively clear-cut and easy to use. They have standardized and intuitive formatting where files always consist of rows that represent data records, and columns that represent their respective attributes. This underlying structure doesn’t require any complex software to open and edit (they can even be manipulated in simple text editors like Notepad or TextEdit), and allows for CSV data to be easily understood by non-technical users. The ability to be used across nearly every platform makes CSV files an incredibly popular choice when in the area of data exchange between different systems. They’re also the most used file type when users need to import or export data across different platforms or within an application.
Efficiency
Efficiency is another key benefit that CSV files offer. Their simple, lightweight structure that lacks any formatting or styling that would otherwise increase the file size or slow down their performance. Their compact nature also allows them to be easily compressed and emailed.
CSV data can be generated, stored, and transferred easily, making them ideal for scenarios where data needs to be exchanged or analyzed quickly. This characteristic is also particularly beneficial when dealing with large volumes of data that wouldn’t be performant when put into other file formats. Additionally, CSV files are compatible with version control systems, supporting detailed tracking of changes over time.
{{blog-content-cta}}
Limitations of CSV files and common problems
User error and improperly formatted CSV data
While CSV files can provide a simple way of storing and transferring data, they are unstandardized and prone to user-error. Although the CSV format has been used for decades, there’s no standardized format enforced across applications. In 2005, the RFC 4180 was released, but most platforms don’t follow it (e.g. Microsoft Excel explicitly does not). Users can often accidentally enter incorrect or incomplete data, such as duplicate headers, missing values, incorrect data in fields (such as emails missing the “@” symbol), or unsupported characters (causing encoding issues).
As the name suggests, CSV data is typically separated by commas. Because of this, most standard libraries expect a comma as the delimiter, and require you to manually overwrite the configuration if the separator is not a comma (e.g. the col_sep setting in Ruby). It’s also possible to write code that attempts to detect the delimiter used in a file, however, encountering uncommon cell delimiters can cause major issues and require manual review before the data can be properly loaded.
Since they can cause a number of downstream data management issues, it’s critical to ensure that the data imported from CSV files is accurate, complete, and consistent with the intended format. Applications typically need to receive CSV files in a particular structure (and with correctly entered data) to avoid unexpected behavior or invalid analyses.
For example, if contacts are uploaded into a CRM through a CSV file that has missing fields, email campaigns like the one below may be sent out if steps aren’t taken to clean up the file first:
Because of the negative impacts from improperly formatted data, systems will often block imports that aren’t don’t match the exact specifications they expect (whether it’s that all header rows must match, there are not duplicate emails, every first and last name are in proper case, etc.), preventing users from progressing to the core value of a product until they’re able to reformat the file appropriately.
Data transfer challenges
Since exporting csv files is a common feature in most web applications, the CSV format is a common method of file transfer. For complex datasets or ones that must be imported in a specific format, investing time building a CSV import flow that instructs users through cleaning and formatting their CSV data before importing the file can also help – especially when specific, complex formatting of the file is necessary. For applications where a user is importing CSV files, if there are strict validation requirements, a lack of guidance during the import process can result in an influx of support ticket requests. Because of the endless possibilities on the types of formatting and data entry errors, resolving import errors often requires manual debugging from technical and non-technical team members, and causes customers to drop off during onboarding processes due to added frustrations.
High memory usage and performance at scale
Most 3rd party tools that handle importing CSVs don’t support large file sizes (e.g. 10M rows), and are not performant at sizes above 1M rows. This is because most point solutions load, validate, and visualize spreadsheet data all at once on the browser rather than a more performant design (such as an in-memory Rust data service that allows for real-time processing, regardless of file size). As CSV data scales to millions of rows, additional features such as caching are required to ensure speed is maintained while visualizing and validating data.
Data transformation is often challenging with large CSV files. When working with programs like Excel or Google Sheets, there are also typically size limits on CSV files. You can only import or export up to 1,048,576 rows or 16,384 columns in Excel, and 5,000,000 cells (with a maximum of 256 columns per sheet) in Google Sheets.
CSV file security concerns
While the CSV file format offers numerous advantages, it also has potential security risks to be mindful of. One of the most notable vulnerabilities is CSV Injections (also known as Formula Injections). CSV Injection is a security vulnerability that occurs when a CSV file containing malicious input is interpreted by a spreadsheet program (such as Microsoft Excel or Google Sheets). Specifically, these attacks can be executed when the CSV data includes entries that are interpreted as formulas by these spreadsheet programs.
For example, an attacker can insert a string like "=cmd|' /C calc'!A0" into a CSV file. When this file is opened in a spreadsheet program, it interprets the string as a formula, and in this case, it would execute a command (in this case, launching the calculator application). More harmful commands could potentially compromise the system or network.
Below are some other security concerns associated with CSV files:
Data Integrity: CSV files do not support encryption or password protection. This means that they can be opened by anyone with access to the file, potentially compromising the integrity and confidentiality of the data.
Data Leakage: Since CSV files are plain text, they can be easily read if intercepted during transmission or if stored without adequate protection. This could lead to data leakage, especially if the data is sensitive or confidential.
Lack of Data Validation: CSV files do not have built-in mechanisms for data validation. This means they could contain erroneous or malicious data, which could lead to inaccurate analyses or security vulnerabilities.
To mitigate these security risks, it's important to validate and sanitize data before it's written into a CSV file, treat all CSV files from untrusted sources as potentially dangerous, and consider the use of more secure file formats when handling sensitive data.
Comparing CSV, JSON, and XML
CSV, JSON, and XML are three of the most common formats for storing and transferring data. Each of these formats has its own unique properties that make them well suited for different types of use cases.
CSVs vs. JSON
The primary difference between CSV and JSON is the way data is stored. The CSV format stores data in a tabular format, with rows representing records and columns representing fields. JSON, on the other hand, uses a hierarchical structure of nested key-value pairs. JSON is not typically used with spreadsheet applications like Microsoft Office, OpenOffice, Airtable, or Google Sheets.
CSV vs. XML
Like CSV, XML stores data in a tabular format with rows representing records and columns representing fields. However, XML also uses tags to define elements and attributes to define their properties. This also means XML generally provides more structure and flexibility when compared to CSV. XML allows you to define custom tags and attributes, which makes it well-suited for document-based data.
Choosing the right file format
Here are some general guidelines when deciding what file format to use:
CSV: For tabular data where a simple format that's easy to read and write is needed.
JSON: When building a web application or API where a lightweight format that's easy to parse and generate in JavaScript is needed.
XML: For document-based data like invoices, reports, or other business documents (CSV can also be used in this case depending on the structure of the data).
Ultimately, the choice of format depends on the specific needs of your application and the data you're working with.
Building a CSV importer
While building a basic importer is straightforward, there are numerous advanced features to consider when launching a CSV importer for production use cases. Spreadsheet import can be an awful experience in so many products due to data tools lacking the advanced features necessary to handle messy data. When users are faced with messages like “error on line 53”, they can end up never getting started with the product.
If you're planning to build a CSV import feature yourself, here are our recommended best practices. However, integrating high quality spreadsheet import capabilities into a product can become a never-ending sink for engineering and support resources that many teams don’t have the resources to launch. Due to the constant edge cases that can occur from user error, teams have to constantly add validations and continue QA testing over 6 months after the initial feature launch.
Instead of spending months writing data validations and handing CSV parsing edge cases, integrating CSV import tools such as OneSchema can allow you to focus your development resources on your core product.Companies like Scale AI and Ramp are using OneSchema to make it fast and easy to launch delightful spreadsheet import experiences, from embeddable CSV import, to importing CSVs from an SFTP folder on a recurring basis. OneSchema intelligently corrects messy data so you can improve your customer activation rates and launch better onboarding experiences than your competitors.
CSV files (“comma separated value files'', or “comma delimited files”) are one of the most common formats for spreadsheet programs. CSV files are plain text files where commas are used to delimit (separate) data. Because the CSV files provide a simple and standardized format that can be easily read and processed by most software applications, they’re widely used across multiple industries to exchange data.
In this article, we’ll provide a comprehensive guide to:
What CSV files are
Common CSV file use cases
CSVs compared with other common file formats (JSON and XML)
The main advantages of using CSV files
The limitations, drawbacks, and common problems with CSV files
What is a CSV file?
CSV files are plain text files where the values in each row are separated by commas, and each row is ended by a line break. The CSV file format is one of the most common formats for sending and storing tabular data.
What does CSV stand for?
"CSV" stands for "comma-separated values". In the CSV file format, commas are used to separate the values in different cells in a spreadsheet data format.
What is .csv?
The ".csv" file extension is used for files in the CSV (comma-separated values) format. While the .csv format has a defined structure, .csv files are often inconsistency formatted, leading to challenges with file parsing and CSV data import.
How is a CSV file structured?
CSV files are plain text files where the values in each row are separated by commas, and each row is ended by a line break.
The relatively simple structure of CSV data allows it to be human-readable, and viewable in many programs including text editors such as TextEdit or Notepad. CSV files often contain a header row at the top which specifies the titles of each column in the file.
Spreadsheet applications, such as Microsoft Excel, convert CSV files into a tabular format, with each row representing a record and each column representing a field.
CSV files end with the extension “.csv”, and the simple structure of CSV data makes it an efficient format for storing and transferring data between different applications.
CSV file delimiters
The CSV file format is one of several "delimited text file" formats. Aside from commas, other common delimiters used in CSV files include:
Semicolons (;)
Pipes (|)
Tabs ( )
Quotes (“, ‘)
For example, in the dataset "jane;doe;FL", the semicolon (;) separates the three data items jane, doe, and FL. If pipes were used as the delimiter instead, the dataset would read “jane|doe|FL”.
Understanding how to use delimiters seems fairly straightforward, but once you’re working with actual datasets, problems arise quickly. For example, how do you handle a comma in a value where commas are also being used as the delimiter for the file? One option would be to surround that value in double quotes, but what if the quote character is also being used inside that value? How about the situation where a newline is used to separate each record, but it’s also present inside of an entry?
Properly handling these complications are often dependent on the platform, so depending on where the CSV data was exported from, a different set of rules in order needs to be applied to properly interpret the dataset.
When are CSV files used?
Because CSV files are designed to be relatively simple, they’re frequently used across a wide range of industries to transfer complicated data between applications. With CSV files, it’s possible to export complicated data from one application to a CSV format, and then import that exported CSV data into another application where it can be used.
Another one of the most common CSV file use cases is for uploading a list of contacts into an application. This can be used to send marketing campaigns through an email delivery platform like SendGrid, or synching customer information into a CRM like Salesforce.
CSV file use cases span across various industries and professions, from business and finance to science and research. Some of the most common CSV use cases include:
Data Import and Export: One of the most common use cases for CSV files is data import and export. Given their simplicity and compatibility, CSV files are often used to transfer data between different types of software, applications, and databases. For instance, a user might export data from a MySQL database into a CSV file for use in an Excel spreadsheet or a Python data analysis tool like pandas.
Data Analysis: CSV files are a popular choice in data analysis due to their compatibility with various data analysis tools and languages, such as R, Python, and SQL. Analysts can easily manipulate and analyze data stored in CSV files, making them a common format for storing datasets.
Data Migration: When migrating data from one system to another, CSV files are often used due to their simplicity and compatibility. For example, when moving customer data from one Customer Relationship Management (CRM) system to another, the data might be exported to a CSV file and then imported into the new system.
Data Backup: CSV files can be used to create backups of data. Given their simplicity and plain text format, CSV files can be a good choice for creating readable, accessible backups of important data.
Reporting: CSV files are often used for generating reports, especially for data-heavy applications. These reports can then be easily opened, manipulated, and analyzed using spreadsheet software.
Machine Learning: In machine learning, CSV files are often used to store training datasets. These files can be easily loaded into machine learning libraries like scikit-learn in Python, where they can be used to train various types of models.
While CSV files have their limitations and potential security concerns, their simplicity, versatility, and wide acceptance make them a go-to choice for many data-related tasks.
Opening and editing CSV files
Opening CSV files with Excel
Microsoft Excel is the most widely used spreadsheet application for opening and editing CSV files, however tools like Numbers for Mac or Google Sheets are also common. In this section, we’ll focus on Excel.
To open a CSV file, simply double-click the file or open it from the Excel program. Once opened, you can edit any cell by clicking on it and modifying its contents directly in that cell or in the area called fx, which stands for “Excel Functions.”
If you want to create a new CSV file, open Microsoft Excel and save a new file as a CSV. You can then edit it and it will continue to save as a CSV whenever you click save. To get started, create the headings for your columns. For example, if you want to create a list of contact information for your team, create one column for first names, another for last names, another for phone numbers, and another for email addresses.
Finally, it’s worth noting that besides CSV files, there are other file formats that can be used for spreadsheets. When working in Google Sheets, for example, you can download the file in several different formats, including Microsoft Excel (.xlsx), OpenDocument format (.ods), PDF document (.pdf), Web page (.html), and tab-separated values (.tsv). Excel also offers numerous formatting options, including: Excel Workbook (.xlsx), Excel Macro-Enabled Workbook (.xlsm), Excel Binary Workbook (.xlsb), Excel 97-2003 Workbook (.xls), XML Data (.xml), and many more.
Reading CSV Files into Python using Pandas
Most programming languages have a CSV parsing library (e.g. here is Python’s, which is part of their standard library).
Pandas is a data manipulation and analysis library for Python, which can be helpful for performing complex transformations and analyses on CSV data. One of the drawbacks is it’s not performant on large datasets (e.g. multiple GB), so depending on the size of CSV data you’re working with it may not be an option. CSV data from Pandas can also be exported into many different formats.
CSV command line tools
For some use cases, command line tools like xsv and csvkit can be great options. xsv is able to function quickly even with large files of >1GB, and allows you to perform simple functions like sorting, reformatting, and fixing data. For more complex data transformations, csvkit has more built in features (e.g. allowing you to convert between CSV and other formats), but isn’t as performant as xsv for larger files.
Relational and hosted databases
Relational databases generally have built-in functions to import or export from CSVs, and can be a good choice for working with complex transformations on large datasets. For extremely large amounts of data (10+ GBs), hosted tools like Redshift and BigQuery, which are columnar databases, allow you to not have to worry about setting up a database server.
Handling special characters in CSV files
In CSV files, a special character is any character that is not alphabetic or numeric.
While there are no limits of what characters can be used in a CSV file, the way the file is encoded will determine the restrictions. UTF-8 is generally the recommended encoding for CSV files because it supports almost every possible character. When opening a CSV in a program other than a text editor (such as Excel), symbols like "??????" and "Êæ§ÖÂ" will be displayed if a character is unsupported. To fix this issue, import CSV files into Excel using the Text Import Wizard and select the proper encoding as the file origin.
Converting CSV files
There are several methods of converting CSV files. You can convert CSV files into other file formats like .xlsx with utilities like CloudConvert, or just by opening the file in Excel and saving with a different file extension. There are also a large number of libraries for converting spreadsheet files into formats like JSON or XML, like csvtojson.
Advantages of CSV files
The underlying structure of the CSV format often makes them a more viable choice compared to heavier formats such as XML and more complex databases. These structural benefits are particularly impactful in areas involving data transfer, data analysis, data manipulation, and data management.
Broad compatibility
One of the most prominent advantages of the CSV format is its broad compatibility. They’re designed to be universally accessible, with most software applications being able to easily read and process CSV files. This compatibility spans a wide range of databases, various programming languages, and data analysis and visualization tools. All modern spreadsheet applications, include Microsoft Office, Google Sheets, Airtable, and OpenOffice support CSV files.
At their core, CSV files are designed to be relatively clear-cut and easy to use. They have standardized and intuitive formatting where files always consist of rows that represent data records, and columns that represent their respective attributes. This underlying structure doesn’t require any complex software to open and edit (they can even be manipulated in simple text editors like Notepad or TextEdit), and allows for CSV data to be easily understood by non-technical users. The ability to be used across nearly every platform makes CSV files an incredibly popular choice when in the area of data exchange between different systems. They’re also the most used file type when users need to import or export data across different platforms or within an application.
Efficiency
Efficiency is another key benefit that CSV files offer. Their simple, lightweight structure that lacks any formatting or styling that would otherwise increase the file size or slow down their performance. Their compact nature also allows them to be easily compressed and emailed.
CSV data can be generated, stored, and transferred easily, making them ideal for scenarios where data needs to be exchanged or analyzed quickly. This characteristic is also particularly beneficial when dealing with large volumes of data that wouldn’t be performant when put into other file formats. Additionally, CSV files are compatible with version control systems, supporting detailed tracking of changes over time.
{{blog-content-cta}}
Limitations of CSV files and common problems
User error and improperly formatted CSV data
While CSV files can provide a simple way of storing and transferring data, they are unstandardized and prone to user-error. Although the CSV format has been used for decades, there’s no standardized format enforced across applications. In 2005, the RFC 4180 was released, but most platforms don’t follow it (e.g. Microsoft Excel explicitly does not). Users can often accidentally enter incorrect or incomplete data, such as duplicate headers, missing values, incorrect data in fields (such as emails missing the “@” symbol), or unsupported characters (causing encoding issues).
As the name suggests, CSV data is typically separated by commas. Because of this, most standard libraries expect a comma as the delimiter, and require you to manually overwrite the configuration if the separator is not a comma (e.g. the col_sep setting in Ruby). It’s also possible to write code that attempts to detect the delimiter used in a file, however, encountering uncommon cell delimiters can cause major issues and require manual review before the data can be properly loaded.
Since they can cause a number of downstream data management issues, it’s critical to ensure that the data imported from CSV files is accurate, complete, and consistent with the intended format. Applications typically need to receive CSV files in a particular structure (and with correctly entered data) to avoid unexpected behavior or invalid analyses.
For example, if contacts are uploaded into a CRM through a CSV file that has missing fields, email campaigns like the one below may be sent out if steps aren’t taken to clean up the file first:
Because of the negative impacts from improperly formatted data, systems will often block imports that aren’t don’t match the exact specifications they expect (whether it’s that all header rows must match, there are not duplicate emails, every first and last name are in proper case, etc.), preventing users from progressing to the core value of a product until they’re able to reformat the file appropriately.
Data transfer challenges
Since exporting csv files is a common feature in most web applications, the CSV format is a common method of file transfer. For complex datasets or ones that must be imported in a specific format, investing time building a CSV import flow that instructs users through cleaning and formatting their CSV data before importing the file can also help – especially when specific, complex formatting of the file is necessary. For applications where a user is importing CSV files, if there are strict validation requirements, a lack of guidance during the import process can result in an influx of support ticket requests. Because of the endless possibilities on the types of formatting and data entry errors, resolving import errors often requires manual debugging from technical and non-technical team members, and causes customers to drop off during onboarding processes due to added frustrations.
High memory usage and performance at scale
Most 3rd party tools that handle importing CSVs don’t support large file sizes (e.g. 10M rows), and are not performant at sizes above 1M rows. This is because most point solutions load, validate, and visualize spreadsheet data all at once on the browser rather than a more performant design (such as an in-memory Rust data service that allows for real-time processing, regardless of file size). As CSV data scales to millions of rows, additional features such as caching are required to ensure speed is maintained while visualizing and validating data.
Data transformation is often challenging with large CSV files. When working with programs like Excel or Google Sheets, there are also typically size limits on CSV files. You can only import or export up to 1,048,576 rows or 16,384 columns in Excel, and 5,000,000 cells (with a maximum of 256 columns per sheet) in Google Sheets.
CSV file security concerns
While the CSV file format offers numerous advantages, it also has potential security risks to be mindful of. One of the most notable vulnerabilities is CSV Injections (also known as Formula Injections). CSV Injection is a security vulnerability that occurs when a CSV file containing malicious input is interpreted by a spreadsheet program (such as Microsoft Excel or Google Sheets). Specifically, these attacks can be executed when the CSV data includes entries that are interpreted as formulas by these spreadsheet programs.
For example, an attacker can insert a string like "=cmd|' /C calc'!A0" into a CSV file. When this file is opened in a spreadsheet program, it interprets the string as a formula, and in this case, it would execute a command (in this case, launching the calculator application). More harmful commands could potentially compromise the system or network.
Below are some other security concerns associated with CSV files:
Data Integrity: CSV files do not support encryption or password protection. This means that they can be opened by anyone with access to the file, potentially compromising the integrity and confidentiality of the data.
Data Leakage: Since CSV files are plain text, they can be easily read if intercepted during transmission or if stored without adequate protection. This could lead to data leakage, especially if the data is sensitive or confidential.
Lack of Data Validation: CSV files do not have built-in mechanisms for data validation. This means they could contain erroneous or malicious data, which could lead to inaccurate analyses or security vulnerabilities.
To mitigate these security risks, it's important to validate and sanitize data before it's written into a CSV file, treat all CSV files from untrusted sources as potentially dangerous, and consider the use of more secure file formats when handling sensitive data.
Comparing CSV, JSON, and XML
CSV, JSON, and XML are three of the most common formats for storing and transferring data. Each of these formats has its own unique properties that make them well suited for different types of use cases.
CSVs vs. JSON
The primary difference between CSV and JSON is the way data is stored. The CSV format stores data in a tabular format, with rows representing records and columns representing fields. JSON, on the other hand, uses a hierarchical structure of nested key-value pairs. JSON is not typically used with spreadsheet applications like Microsoft Office, OpenOffice, Airtable, or Google Sheets.
CSV vs. XML
Like CSV, XML stores data in a tabular format with rows representing records and columns representing fields. However, XML also uses tags to define elements and attributes to define their properties. This also means XML generally provides more structure and flexibility when compared to CSV. XML allows you to define custom tags and attributes, which makes it well-suited for document-based data.
Choosing the right file format
Here are some general guidelines when deciding what file format to use:
CSV: For tabular data where a simple format that's easy to read and write is needed.
JSON: When building a web application or API where a lightweight format that's easy to parse and generate in JavaScript is needed.
XML: For document-based data like invoices, reports, or other business documents (CSV can also be used in this case depending on the structure of the data).
Ultimately, the choice of format depends on the specific needs of your application and the data you're working with.
Building a CSV importer
While building a basic importer is straightforward, there are numerous advanced features to consider when launching a CSV importer for production use cases. Spreadsheet import can be an awful experience in so many products due to data tools lacking the advanced features necessary to handle messy data. When users are faced with messages like “error on line 53”, they can end up never getting started with the product.
If you're planning to build a CSV import feature yourself, here are our recommended best practices. However, integrating high quality spreadsheet import capabilities into a product can become a never-ending sink for engineering and support resources that many teams don’t have the resources to launch. Due to the constant edge cases that can occur from user error, teams have to constantly add validations and continue QA testing over 6 months after the initial feature launch.
Instead of spending months writing data validations and handing CSV parsing edge cases, integrating CSV import tools such as OneSchema can allow you to focus your development resources on your core product.Companies like Scale AI and Ramp are using OneSchema to make it fast and easy to launch delightful spreadsheet import experiences, from embeddable CSV import, to importing CSVs from an SFTP folder on a recurring basis. OneSchema intelligently corrects messy data so you can improve your customer activation rates and launch better onboarding experiences than your competitors.