1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

SASで適当なデータ(テストデータ?)を作るときのプログラムをPythonで。

Last updated at Posted at 2019-02-26

適当なデータを作る時に,SASではこんな書き方をしてデータを作ってました。

sas_testdata.sas
data testdata;
  do SUBJID = 10 to 1100 by 10;
    do VISIT = -1 , 1 to 5;
      VALUE = rand("normal",0,1);
      output;
    end;
  end;
run;

pythonで書くと,こんな感じになりそうです。

python_testdata.py
import pandas as pd
import numpy as np

SUBJIDs = np.arange(10, 1100 ,10)
VISITs   = np.array([-1,1,2,3,4,5])

testdata = pd.DataFrame([(SUBJID, VISIT, np.random.normal(0,1))
                        for SUBJID in SUBJIDs
                        for VISIT in VISITs]
                        ,columns=['SUBJID', 'VISIT', 'VALUE']
                        )
testdata.head(10)

もっと良い方法がありそうではありますが,現状こんな書き方をしています。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?