• Skip to main content
  • Skip to primary sidebar

学習記録

DataFrame 列の追加とindexの追加 縦に増やす

2017年11月25日 by 河副 太智 Leave a Comment

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<span role="presentation"><span class="cm-keyword">DataFrame 列の追加とindexの追加 縦に増やす
 
import pandas as pd
​
index = ["a", "b", "c", "d", "e"]
data1 = [10, 5, 8, 12, 3]
data2 = [30, 25, 12, 10, 8]
series1 = pd.Series(data1, index=index)
series2 = pd.Series(data2, index=index)
​
new_column = pd.Series([15, 7], index=[0, 1])
#縦(カラム)に15と7を代入、indexで15を縦の0の位置に入れ、1を縦の1の位置に代入
​
# series1, seires2からDataFrameを生成
df = pd.DataFrame([series1, series2])
​
# dfの新しい列"f"にnew_columnのデータを追加
df["f"] = new_column
​
# 出力
print(df)</span></span>
1
2
3
    a   b   c   d  e   f
0  10   5   8  12  3  15
1  30  25  12  10  8   7
このエントリーをはてなブックマークに追加

Tweet
[`yahoo` not found]
このエントリーを Google ブックマーク に追加
LinkedIn にシェア
LINEで送る


Filed Under: Pandas

Reader Interactions

コメントを残す コメントをキャンセル

メールアドレスが公開されることはありません。 ※ が付いている欄は必須項目です

Primary Sidebar

カテゴリー

  • AWS
  • Bootstrap
  • Dash
  • Django
  • flask
  • GIT(sourcetree)
  • Plotly/Dash
  • VPS
  • その他tool
  • ブログ
  • プログラミング
    • Bokeh
    • css
    • HoloViews
    • Jupyter
    • Numpy
    • Pandas
    • PosgreSQL
    • Python 基本
    • python3
      • webアプリ
    • python3解説
    • scikit-learn
    • scipy
    • vps
    • Wordpress
    • グラフ
    • コマンド
    • スクレイピング
    • チートシート
    • データクレンジング
    • ブロックチェーン
    • 作成実績
    • 時系列分析
    • 機械学習
      • 分析手法
      • 教師有り
    • 異常値検知
    • 自然言語処理
  • 一太郎
  • 数学
    • sympy
      • 対数関数(log)
      • 累乗根(n乗根)
    • 暗号学

Copyright © 2025 · Genesis Sample on Genesis Framework · WordPress · Log in