Last active
January 7, 2021 14:32
-
-
Save ImkeF/9e30713789aa50e7e52c4a161af624a7 to your computer and use it in GitHub Desktop.
Exports table to csv using Python-script.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let func = | |
(SOURCE as table, PATH as text, optional mode as text, optional index as logical, optional header as logical, optional quoting as text, optional chunksize as number, optional decimal_as_point as text) => | |
let | |
Source = Table.TransformColumnTypes(SOURCE, List.Transform(Table.ColumnNames(SOURCE), each {_, type text})), | |
Path = PATH, | |
index = if index = null then "None" else "True", | |
header = if header = null then "True" else "False", | |
quoting = if quoting = null then "csv.QUOTE_ALL" else quoting, | |
chunksize = if chunksize = null then "None" else chunksize, | |
//Edit by RonaiBertalan (https://gist.github.com/RonaiBertalan): | |
decimal_as_point = if decimal_as_point = null then "'.'" else "','", | |
CleanedPath = Text.Replace(Path, "\", "/"), | |
Custom1 = Python.Execute("# 'dataset' holds the input data for this script#(lf)#(lf)import csv #(lf)import pandas as pd#(lf)path = r'"& CleanedPath &"'#(lf)#(lf)dataset.to_csv(path, mode = 'w', index = " & index & ", header = " & header & ", quoting = " & quoting & ", chunksize = " & chunksize & ", decimal= " & decimal_as_point & ")",[dataset=Source]) | |
in | |
Custom1 , | |
documentation = [ | |
Documentation.Name = " Table.ExportCsvPyhton.pq ", | |
Documentation.Description = " Exports table to csv using Python-script. ", | |
Documentation.LongDescription = " Exports table to csv using Python-script. Defaults to: index-None, header-True, quoting-None, chunksize-None. ", | |
Documentation.Category = " Table ", | |
Documentation.Source = " ", | |
Documentation.Version = " 1.1: QUOTE_ALL ", | |
Documentation.Author = " Imke Feldmann: www.TheBIccountant.com. ", | |
Documentation.Examples = {[Description = " ", | |
Code = " ", | |
Result = " "]}] | |
in | |
Value.ReplaceType(func, Value.ReplaceMetadata(Value.Type(func), documentation)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
`let func =
(SOURCE as table, PATH as text, optional mode as text, optional index as logical, optional header as logical, optional quoting as text, optional decimal_as_point as logical, optional chunksize as number) =>
let
Source = Table.TransformColumnTypes(SOURCE, List.Transform(Table.ColumnNames(SOURCE), each {_, type text})),
Path = PATH,
index = if index = null then "None" else "True",
header = if header = null then "True" else "False",
quoting = if quoting = null then "csv.QUOTE_ALL" else quoting,
chunksize = if chunksize = null then "None" else chunksize,
decimal_as_point = if decimal_as_point = null then "'.'" else "','",
CleanedPath = Text.Replace(Path, "", "/"),
Custom1 = Python.Execute("# 'dataset' holds the input data for this script#(lf)#(lf)import csv #(lf)import pandas as pd#(lf)path = r'"& CleanedPath &"'#(lf)#(lf)dataset.to_csv(path, mode = 'w', index = " & index & ", header = " & header & ", quoting = " & quoting & ", chunksize = " & chunksize & ", decimal= " & decimal_as_point & " )",[dataset=Source])
in
Custom1 ,
documentation = [
Documentation.Name = " Table.ExportCsvPyhton.pq ",
Documentation.Description = " Exports table to csv using Python-script. ",
Documentation.LongDescription = " Exports table to csv using Python-script. Defaults to: index-None, header-True, quoting-None, chunksize-None, decimal='.' ",
Documentation.Category = " Table ",
Documentation.Source = " ",
Documentation.Version = " 1.1: QUOTE_ALL ",
Documentation.Author = " Imke Feldmann: www.TheBIccountant.com. ",
Documentation.Examples = {[Description = " ",
Code = " ",
Result = " "]}]
in
Value.ReplaceType(func, Value.ReplaceMetadata(Value.Type(func), documentation))`