Linux command
csvpy 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Open a CSV file
csvpy [data.csv]
Open with tab delimiter
csvpy -t [data.tsv]
Load as an agate Table
csvpy --agate [data.csv]
Load as DictReader
csvpy --dict [data.csv]
Open with custom encoding
csvpy -e [latin1] [data.csv]
Open file without headers
csvpy -H [data.csv]
Open with a custom delimiter
csvpy -d "[;]" [data.csv]
说明
csvpy is part of csvkit that loads a CSV file into an interactive Python shell for exploration and analysis. If IPython is installed, it is used as the shell for a richer experience. In default mode, the CSV data is loaded into a variable named reader, a csv.reader object. With --dict, it becomes a DictReader where each row is a dictionary. With --agate, it becomes a table variable with full analysis capabilities including sorting, filtering, and aggregation. This tool is useful for quick data exploration, testing data transformations, and prototyping analysis code. The interactive environment allows immediate feedback while working with the data.
参数
- -d _CHAR_, --delimiter _CHAR_
- Field delimiter character (default: comma).
- -t, --tabs
- Use tab characters as the field delimiter.
- -q _CHAR_, --quotechar _CHAR_
- Character used for quoting fields.
- -e _ENCODING_, --encoding _ENCODING_
- Specify the input file encoding (e.g., utf-8, latin1).
- -H, --no-header-row
- Indicate that the file has no header row.
- -K _N_, --skip-lines _N_
- Skip the first N lines of the input before processing.
- --agate
- Load the file as an agate Table instead of a csv.reader object. The data is available as a variable named table.
- --dict
- Load as a csv.DictReader where each row is a dictionary keyed by column headers.
- -I, --no-inference
- Disable type inference when used with --agate, keeping all values as strings.
- -S
- Disable CSV dialect sniffing.
- --blanks
- Do not convert empty strings to None.
- --null-value _VALUES_
- Convert specified values to None (can specify multiple).
- -y _N_, --sniff-limit _N_
- Limit the number of bytes used for CSV dialect sniffing.
- -l, --linenumbers
- Insert a column of line numbers at the beginning of the output.
- -z _N_, --field-size-limit _N_
- Maximum length of a single field in the input CSV.
- -V, --version
- Display version information.
FAQ
What is the csvpy command used for?
csvpy is part of csvkit that loads a CSV file into an interactive Python shell for exploration and analysis. If IPython is installed, it is used as the shell for a richer experience. In default mode, the CSV data is loaded into a variable named reader, a csv.reader object. With --dict, it becomes a DictReader where each row is a dictionary. With --agate, it becomes a table variable with full analysis capabilities including sorting, filtering, and aggregation. This tool is useful for quick data exploration, testing data transformations, and prototyping analysis code. The interactive environment allows immediate feedback while working with the data.
How do I run a basic csvpy example?
Run `csvpy [data.csv]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -d _CHAR_, --delimiter _CHAR_ do in csvpy?
Field delimiter character (default: comma).