How to :: add your datasources like a pro? 🚀¶
Overview¶
Hey there ! 👋
We all want to drop a file in Toucan Toco (excel, csv…) and directly use it in our charts! Most of the time, the file appears perfectly fine on Toucan.
However, let me show you some very useful tricks and directives that will help you if your datasource doesn’t appear properly in the tool . 😉
Warning
Before dropping or loading your datasource, make sure your file is in a .csv or .xml format.
Sometimes, even when you applied all the requirements for a good flat file as expected by Toucan, you might need to customize the data interpretation done by Toucan to transform a datasource into a domain 🎩
Dtype¶
For both excel and csv files The first tip to keep in mind is that in Toucan numbers appear in blue and the strings in black. When loading a file some numbers can be not recognized as numbers for instance.
It is never too late! You can easily pick your datasource in the data explorer and previsualize it 😄
You have 2 different ways to do it:
- With the visual interface: you can add your dtype parameter, please
write it with a JSON format. For example:
{ "labels": "str" }
- With the code mode interface: you can use the function dtype,
followed by the name of the column and by the type. For example:
dtype: labels : 'str'
Awesome 🎉 Now your variables are in the right format and type!
Dates¶
For some file types, like Excel or Google Sheets, Toucan should be able to understand that some columns contains dates. But for other, like CSVs, there is no way to fnd out automatically :sad_face:
No worries, it’s super easy to tell Toucan which column to parse as date: just tick the box “parse columns as dates” and indicate the names of dates columns.
Once a column is imported as a date, it’ll appear with a calendar icon next to it when creating a query:
Decimals¶
For csv files Another quite tricky situation is when your file is
formatted with decimal separators like the comma (,
) instead of the
international standard (the dot .
).
But again, no problem for Toucan 😉
You have 2 different ways to indicate it:
With the visual interface: you can add your decimal parameter, in the dedicated section. Just write the desired character.
With the code mode interface: you can use the function decimal, followed by the character. For example:
decimal: ","
Awesome part 2 🎉 We’re getting there!
Separators¶
For csv files Last trick that i show you here concerns also the format of the file. As it’s very common in csv file.
We all know sometimes when we open our csv file. All the data is not separated in the different columns and you need to apply your separator directly in excel. This also happens in Toucan. No worries, i got a solution 🙏
You have 2 different ways to do it:
With the visual interface: you can add your separator parameter, in the dedicated section. Just write the desired character.
With the code mode interface: you can use the function sep, followed by the character. For example:
sep: ","
💡 Note that these options come from the pandas library we use to interpret the files. If you want to check all the options available, you can find them under the following links:
- for csv: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.read_csv.html
- for excel: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.read_excel.html
Let’s go !