Ready to get started?

Learn more about the Quandl PowerShell Cmdlets or download a free trial:

Download Now

PowerShell でQuandl Data データをCSV に落としてみた

標準PowerShell cmdlets を使ってQuandl テーブルにアクセス。

CData Cmdlets Module for Quandl は、直感的なQuandl データ連携を提供する標準cmdlet です。 本記事では、Quandl Cmdlets を使ったサンプルを提供します。

Creating a Connection to Your Quandl Data

Quandl uses an API key for authentication. See the help documentation for a guide to obtaining the APIKey property.

Additionally, set the DatabaseCode connection property to the code identifying the Database whose Datasets you want to query with SQL. You can search the available Databases by querying the Databases view.

$conn = Connect-Quandl  -APIKey "$APIKey" -DatabaseCode "$DatabaseCode"

Selecting Data

Follow the steps below to retrieve data from the AAPL table and pipe the result into to a CSV file:

Select-Quandl -Connection $conn -Table AAPL | Select -Property * -ExcludeProperty Connection,Table,Columns | Export-Csv -Path c:\myAAPLData.csv -NoTypeInformation

You will notice that we piped the results from Select-Quandl into a Select-Object cmdlet and excluded some properties before piping them into an Export-Csv cmdlet. We do this because the CData Cmdlets append Connection, Table, and Columns information onto each "row" in the result set, and we do not necessarily want that information in our CSV file.

The Connection, Table, and Columns are appended to the results in order to facilitate piping results from one of the CData Cmdlets directly into another one.

Deleting Data

The following line deletes any records that match the criteria:

Select-Quandl -Connection $conn -Table AAPL -Where "Collapse = Daily" | Remove-Quandl

Inserting and Updating Data

The cmdlets make data transformation easy as well as data cleansing. The following example loads data from a CSV file into Quandl, checking first whether a record already exists and needs to be updated instead of inserted.

Import-Csv -Path C:\MyAAPLUpdates.csv | %{
  $record = Select-Quandl -Connection $Quandl -Table AAPL -Where ("ID = `'"+$_.ID+"`'")
  if($record){
    Update-Quandl -Connection $quandl -Table AAPL -Columns ("Date","Volume") -Values ($_.Date, $_.Volume) -Where ("ID = `'"+$_.ID+"`'")
  }else{
    Add-Quandl -Connection $quandl -Table AAPL -Columns ("Date","Volume") -Values ($_.Date, $_.Volume)
  }
}

As always, our goal is to simplify the way you connect to data. With cmdlets users can install a data module, set the connection properties, and start building. Download Cmdlets and start working with your data in PowerShell today!

 
 
ダウンロード