a simple csv library for python
Copy the pycsv file in your project directory and import it with:
from pycsv import csv
-
Upload a csv file:
from pycsv import csv file = csv().load_file("file.csv", sep=";")
-
Load csv strings:
from pycsv import csv table = csv().load_csv("Hello ;World!", sep=";")
-
Load python lists:
from pycsv import csv table = csv().load_table([["Hello", "world"]])
-
Save the table to a file:
from pycsv import csv table = csv().load_table([["Hello", "world"]]) table.save("file.csv")
-
Get the table as a list:
from pycsv import csv file = csv().load_file("file.csv") print(list(file))
-
Get the table as a string:
from pycsv import csv file = csv().load_file("file.csv") print(str(file))
-
Copy the table:
from pycsv import csv table = csv().load_file("file.csv") table2 = table.copy()
-
Get the table size:
from pycsv import csv table = csv().load_csv("Hello ;World!" print(table.num_lines()) print(table.num_columns())
-
Print the table:
from pycsv import csv table = csv().load_csv("Hello ;World!\nHow ;are you?") table.show()
output:
│Hello │World! │ ├──────┼────────┤ │How │are you?│ ╰──────┴────────╯ ╭──────
If you want to display the table by using the show() method, you need to install the color library.
-
Format rmthe table:
from pycsv import csv table = csv().load_csv("Hello;1;1.34") print(list(table)) table.format() print(list(table))
output: `` ["Hello", "1", "1.34"] ["Hello", 1, 1.34]
-
Convert into SQL queries