Spreadsheets often export CSV (comma seperated values) files, because they are easy to read and write. A csv file is simply consists of values, commas and newlines. While the file is called ‘comma seperate value’ file, you can use another seperator such as the pipe character.
Data Analysis in Python with Pandas
Create a spreadsheet file (CSV) in Python
Let us create a file in CSV format with Python. We will use the comma character as seperator or delimter.
Running this code will give us this fil persons.csv with this content:
You can import the persons.csv file in your favorite office program.
Read a spreadsheet file (csv)
If you created a csv file, we can read files row by row with the code below:
This will simply show every row as a list:
Perhaps you want to store that into Python lists. We get the data from the csv file and then store it into Python lists. We skip the header with an if statement because it does not belong in the lists. Full code:
['Derek', 'Steve', 'Paul']
Most spreadsheet or office programs can export csv files, so we recommend you to create any type of csv file and play around with it :-)