plsql中导入csvs_在命令行中使用sql分析csvs
plsql中導(dǎo)入csvs
If you are familiar with coding in SQL, there is a strong chance you do it in PgAdmin, MySQL, BigQuery, SQL Server, etc. But there are times you just want to use your SQL skills for quick analysis on a small/medium sized dataset.
如果您熟悉SQL編碼,則很有可能在PgAdmin , MySQL , BigQuery , SQL Server等中進(jìn)行編碼。但是有時(shí)您只想使用SQL技能來(lái)對(duì)中小型大小進(jìn)行快速分析。數(shù)據(jù)集。
With csvkit you can run any SQL on your CSV files right in your command line.
使用csvkit您可以在命令行中直接在CSV文件上運(yùn)行任何SQL。
csvkit is a suite of command-line tools for converting to and working with CSV, the king of tabular file formats. Once you have csvkit installed you can use csvsql to run your SQL commands.
csvkit是一套命令行工具,用于轉(zhuǎn)換為表格格式文件之王CSV并與其一起使用。 一旦你有csvkit安裝就可以使用csvsql來(lái)運(yùn)行SQL命令。
1.安裝 (1. Installation)
If you don’t have csvkit installed, head over here and follow the installation instructions or if you’re familiar with pip you can do the following.
如果您沒(méi)有安裝csvkit ,請(qǐng)csvkit 此處并按照安裝說(shuō)明進(jìn)行操作,或者如果您熟悉pip ,則可以執(zhí)行以下操作。
pip install csvkitYou can view the csvkit documentation using below.
您可以使用以下方法查看csvkit文檔。
csvsql -h2.語(yǔ)法 (2. Syntax)
Now that you are all set up, you can follow this simple structure to run your queries. It is essential to note the SQL query must be written in quotation marks and must be in a single line. No line breaks.
現(xiàn)在您已經(jīng)完成了所有設(shè)置,可以按照以下簡(jiǎn)單結(jié)構(gòu)運(yùn)行查詢。 請(qǐng)務(wù)必注意,SQL查詢必須用引號(hào)引起來(lái)并且必須在一行中。 沒(méi)有換行符。
csvsql --query "ENTER YOUR SQL QUERY HERE"FILE_NAME.csv
That’s it! Follow this basic code skeleton, and you are good to go.
而已! 遵循此基本代碼框架,您就可以開(kāi)始工作了。
Make sure you are in the same working directory as where the CSV file is located.
確保您與CSV文件位于同一工作目錄中。
3.例子 (3. Example)
Below is an example of setting the directory and getting our first SQL command up and running in.
以下是設(shè)置目錄并啟動(dòng)并運(yùn)行我們的第一個(gè)SQL命令的示例。
檢查目錄 (Check Directory)
pwd設(shè)置工作目錄 (Set Working Directory)
Make sure the file you plan to use is in the same directory. My CSV file is in the /Documents folder.
確保計(jì)劃使用的文件位于同一目錄中。 我的CSV文件位于/Documents文件夾中。
cd ~/Documents運(yùn)行查詢 (Run Query)
Next, we can run the query usingcsvsql
接下來(lái),我們可以使用csvsql運(yùn)行查詢
code碼 output輸出使用csvlook格式化查詢輸出 (Format Query Output with csvlook)
Piping with | csvlook can improve how your outputted query format.
用| csvlook | csvlook可以改善輸出查詢格式的方式。
code碼 output輸出將查詢輸出保存到新的CSV (Save Query Output to a New CSV)
Using redirection with > you can send you query output to a new file/location. Note running the code below will not output anything, since we are saving the output to a new file. The new query will save the output to the new csv file store_sales.csv
通過(guò)>使用重定向,您可以將查詢輸出發(fā)送到新文件/位置。 請(qǐng)注意,由于我們將輸出保存到新文件中,因此運(yùn)行下面的代碼不會(huì)輸出任何內(nèi)容。 新查詢會(huì)將輸出保存到新的csv文件store_sales.csv
You are all set! Now you can run SQL on your CSV files for quick insights without the need to go through a database.
你們都準(zhǔn)備好了! 現(xiàn)在,您可以在CSV文件上運(yùn)行SQL,以快速了解情況,而無(wú)需通過(guò)數(shù)據(jù)庫(kù)。
If you are looking to learn more about SQL, check out my other articles.
如果您想了解有關(guān)SQL的更多信息,請(qǐng)查看我的其他文章。
SQL Cheatsheet
SQL備忘單
Date/Time Functions in SQL
SQL中的日期/時(shí)間函數(shù)
Using CTEs in SQL
在SQL中使用CTE
Introduction to Window Functions
窗口功能介紹
翻譯自: https://towardsdatascience.com/analyze-csvs-with-sql-in-command-line-233202dc1241
plsql中導(dǎo)入csvs
總結(jié)
以上是生活随笔為你收集整理的plsql中导入csvs_在命令行中使用sql分析csvs的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 梦到吃喜面是什么意思
- 下一篇: 火种 ctf_分析我的火种数据