CSV¶
Read and write CSV files.
Installation¶
Importing the Plugin¶
After you installed this package, the next step is to import the package into your code and start using the functions.
Instantiating the Plugin¶
To make the example we will instantiate the plugin.
Warning
To avoid the EmptyDataError exception when reading empty CSV files, it is important to check if the file contains data before attempting to process it.
Manipulating spreadsheet data¶
Now, let's manipulate some data from our file, adding new data, sorting and writing the result to a new file.
Complete code¶
Let's take a look into the complete code:
from botcity.plugins.csv import BotCSVPlugin
# Instantiate the plugin
bot_csv = BotCSVPlugin()
# Read from a CSV File
bot_csv.read('read.csv')
# Add a row
bot_csv.add_row([0, 22])
# Sort it by columns with header H1 and H2 in descending order
bot_csv.sort(['H1', 'H2'], False)
# Print the result
print(bot_csv.as_list())
# Save it to a new file
bot_csv.write('write.csv')