MENU
  • ホーム
  • Contact Us
Hayashi's discovery-oriented learning | 地域研究と分析の林
地域研究と分析の林
  • ホーム
  • Contact Us
地域研究と分析の林
  • ホーム
  • Contact Us
Youtubeチャンネルはこちら(鉄道趣味メイン)
  1. ホーム
  2. データ前処理と即席可視化
  3. SeriesやDataFrameの作り方

SeriesやDataFrameの作り方

Seriesの作り方

import pandas as pd
new_series = pd.Series(['aa','bb','cc'])

DataFrameの作り方

import pandas as pd
df = pd.DataFrame([['A','53','ga'],['1','tr','21']], columns=['Col1', 'Col2', 'Col3'])
df <- data.frame(Col1 = c('A', '1'), Col2 = c('53', 'tr'), Col3 = c('ga', '21'))

要素をリストで渡せば自動で作ってくれる関数

import pandas as pd

def create_dataframe(elements, rows, columns):
    data = {}
    for i in range(columns):
        column_name = f"列{i + 1}"
        data[column_name] = elements[i * rows: (i + 1) * rows]

    df = pd.DataFrame(data)
    return df
create_dataframe <- function(elem, rows, columns){
    data <- list()
    for ( i in 1:columns) {
        column_name <- paste("列", i, sep="")
        data[[column_name]] <- elem[(i-1) * rows + 1 : i * rows]
    }
    df <- as.data.frame(data)
    return(df)
}
スポンサーリンク
新着記事
  • 鳳派出所の風景(後編)
  • 鳳派出所の風景(中編)
  • 鳳派出所の風景(前編)
おすすめ

Youtubeチャンネル
https://www.youtube.com/watch?v=w2q30VHcXj4
  • ホーム
  • Contact Us

© 地域研究と分析の林.