Pandas,Python

Thumbnail of post image 034
# 列名のみのデータフレーム作成df = pd.DataFrame({'person':,\ 'name':,\ 'num':}) person name num0 a aa 1001 b bb 2002 c cc 3003 a aaa 1 ...

Pandas,Python

Thumbnail of post image 105
import pandas as pdfrom collections import Counterd = Counter({'A': 1, 'B': 2, 'C': 3})df = pd.DataFrame.from_dict(d, or ...

Pandas,Python

Thumbnail of post image 075

from pathlib import Pathdef txt_to_df(str_txt): # TXTをDataframeに変換する、何らかの処理 return dftxt_path = Path("./txt/")all_df = p ...

Pandas,Python

Thumbnail of post image 006

import pandas as pddef func(row): if row < 3: return row + row else: passdf = pd.DataFrame({'A':,'B':,'C':})df = df.a ...

Pandas,Python

Thumbnail of post image 036

import pandas as pddef func(row): if row < 3: return row + row else: return row + rowdf = pd.DataFrame({'A':,'B':,'C' ...

Pandas,Python

Thumbnail of post image 052

import pandas as pddf = pd.read_csv("./train.csv")df = df]

Pandas

Thumbnail of post image 065

サンプル

import pandas as pddf = pd.DataFrame()for i in range(5): tmp_series = pd.Series() df = df.append(tmp_series, ...

Pandas,Python

Thumbnail of post image 123

Windowsでpd.read_csvを使うと頻繁にエラーがでる.

エラーがでにくいcsvの読み込み方を見つけたので,メモ.

df = pd.read_csv("./hoge.csv", engine="python ...

Pandas,Python

Thumbnail of post image 199

hogeというフォルダの中に複数のCSVが配置されているとき、

以下のコードで複数のCSVを一つのDataFrame(表)としてまとめることが可能

from glob import globimport pandas ...

Pandas,Python

Thumbnail of post image 199

# Make DataframeIn:df = pd.DataFrame({"A" : ,"B" : ,"C" : ,"D" : np.random.randn(8)})Out:A B C D0 foo one hoge -0.650722 ...