Quantcast
Channel: かずきのBlog@hatena
Viewing all articles
Browse latest Browse all 1388

PythonでCSVを読み込んで欠損値を穴埋めするよ

$
0
0

まずは、Pythonのインストールから3.5を入れよう。

そしたら、DataFrame扱うためのpandasを以下のコマンドでインストール。

pip install pandas

終わったら以下のようなスクリプトを書いて実行!

import numpy as np
import pandas as pd

df = pd.read_csv('input.csv')
df = df.fillna(method='ffill')
df = df.fillna(method='bfill')

df.to_csv('output.csv', index = False)

Viewing all articles
Browse latest Browse all 1388

Trending Articles