title.rb
import pandas as pd
import numpy as np
# DataFrameの作成
df = pd.DataFrame(columns=['r', 'theta', 'phi'])
# r, theta, phiの値を生成するリスト内包表記
data = [{'r': r, 'theta': theta, 'phi': phi}
for r in range(4, 5) # rの範囲は1~10
for theta in range(-60, 62, 2)
for phi in range(-60, 62, 2)]
# DataFrameにデータを追加
df = df.append(data, ignore_index=True)
df['x'] = df['r'] * np.sin(np.radians(df['theta'].astype(float))) * np.cos(np.radians(df['phi'].astype(float)))
df['y'] = -df['r'] * np.sin(np.radians(df['phi'].astype(float))) / np.cos(np.radians(df['theta'].astype(float)))
df['z'] = df['r'] * np.cos(np.radians(df['theta'].astype(float))) * np.cos(np.radians(df['phi'].astype(float)))
df['r_check'] = (df['x']**2 + df['y']**2 + df['z']**2)**0.5
print(df['r_check'].unique())
# データフレームを表示
df.tail()