vivainsights.import_query¶
Import a Viva Insights query from a CSV file with optimized variable types.
The function takes in a file path (x) and an optional encoding parameter (default is ‘utf-8’). It checks if the file is a .csv file, reads in the file using pandas, cleans the column names by removing spaces and special characters, and returns the resulting data as a pandas dataframe. If there is an error reading the file, the function prints an error message.
- vivainsights.import_query.import_query(x, encoding='utf-8')[source]¶
Import a Viva Insights query from a CSV file.
Reads the file, strips whitespace from column names and replaces spaces and special characters with underscores.
- Parameters:
x (str) – Path to a
.csvfile.encoding (str, optional) – Character encoding for reading the file. Defaults to
"utf-8".
- Returns:
The imported data with cleaned column names.
- Return type:
pandas.DataFrame
- Raises:
ValueError – If the file does not exist, is not a CSV, or cannot be read.
Examples
Import a standard Viva Insights CSV export:
>>> import vivainsights as vi >>> data = vi.import_query("path/to/query.csv")
Specify a custom encoding for non-UTF-8 files:
>>> data = vi.import_query("path/to/query.csv", encoding="latin-1")