read_csvでsep=Noneとengine=’python’とすると自動区切り文字検出モードになる [pandas]
![Thumbnail of post image 043](https://i0.wp.com/vasteelab.com/wp-content/uploads/2020/07/erik-dungan-MQyCrJVFG8U-unsplash.jpg?resize=150%2C150&ssl=1)
Pandasのread_csv関数におけるsep=Noneとengine='python'の使用
pandasは、データ解析やデータ操作に広く使われるPythonのライブラリであり、その中でもCSVファイルを読み込むread_csv関数 ...
[行番号, 列名]で値取得
![Thumbnail of post image 123](https://i0.wp.com/vasteelab.com/wp-content/uploads/2020/07/brooke-lark-nTZOILVZuOg-unsplash.jpg?resize=150%2C150&ssl=1)
# 列名のみのデータフレーム作成df = pd.DataFrame({'person':,\ 'name':,\ 'num':}) person name num0 a aa 1001 b bb 2002 c cc 3003 a aaa 1 ...
CounterをDictionary(辞書)に変換[Python]
![Thumbnail of post image 156](https://i0.wp.com/vasteelab.com/wp-content/uploads/2020/07/mockaroon-bzLhhI3MpYY-unsplash.jpg?resize=150%2C150&ssl=1)
import pandas as pdfrom collections import Counterd = Counter({'A': 1, 'B': 2, 'C': 3})df = pd.DataFrame.from_dict(d, or ...
「TXTを1つずつ読み込んで空のDataframeに結合」を繰り返す [Python][Pandas]
![Thumbnail of post image 030](https://i0.wp.com/vasteelab.com/wp-content/uploads/2020/07/taylor-heery-71sp4JBYO-U-unsplash-2.jpg?resize=150%2C150&ssl=1)
from pathlib import Pathdef txt_to_df(str_txt): # TXTをDataframeに変換する、何らかの処理 return dftxt_path = Path("./txt/")all_df = p ...
条件にpassがある関数をapplyするとNaNが返ってくる[Python][Pandas]
![Thumbnail of post image 052](https://i0.wp.com/vasteelab.com/wp-content/uploads/2020/07/bram-van-oost-6WvZo5FOxww-unsplash.jpg?resize=150%2C150&ssl=1)
import pandas as pddef func(row): if row < 3: return row + row else: passdf = pd.DataFrame({'A':,'B':,'C':})df = df.a ...
pandasで自作関数をapplyするときはaxis=1を設定する[Pandas][Python]
![Thumbnail of post image 131](https://i0.wp.com/vasteelab.com/wp-content/uploads/2020/07/anna-sullivan-IUXR0sqs-mY-unsplash.jpg?resize=150%2C150&ssl=1)
import pandas as pddef func(row): if row < 3: return row + row else: return row + rowdf = pd.DataFrame({'A':,'B':,'C' ...
DataFrameから複数列を抽出[Python][Pandas]
![Thumbnail of post image 142](https://i0.wp.com/vasteelab.com/wp-content/uploads/2020/07/mockaroon-bzLhhI3MpYY-unsplash.jpg?resize=150%2C150&ssl=1)
import pandas as pddf = pd.read_csv("./train.csv")df = df]
空のDataFrameに1行ずつデータを追加[pandas]
![Thumbnail of post image 066](https://i0.wp.com/vasteelab.com/wp-content/uploads/2020/07/erik-dungan-MQyCrJVFG8U-unsplash.jpg?resize=150%2C150&ssl=1)
サンプル
import pandas as pddf = pd.DataFrame()for i in range(5): tmp_series = pd.Series() df = df.append(tmp_series, ...pd.read_csvでUnicodeDecodeErrorがでるときの対処法[Python][Pandas]
![Thumbnail of post image 196](https://i0.wp.com/vasteelab.com/wp-content/uploads/2020/07/georgia-de-lotz-muN_TndU9A0-unsplash.jpg?resize=150%2C150&ssl=1)
Windowsでpd.read_csvを使うと頻繁にエラーがでる.
エラーがでにくいcsvの読み込み方を見つけたので,メモ.
df = pd.read_csv("./hoge.csv", engine="python ...複数のCSVを読み込んで一つのDataframeにまとめる[Python][Pandas]
![Thumbnail of post image 018](https://i0.wp.com/vasteelab.com/wp-content/uploads/2020/07/sambazon-qfIVXu7nxGU-unsplash.jpg?resize=150%2C150&ssl=1)
hogeというフォルダの中に複数のCSVが配置されているとき、
以下のコードで複数のCSVを一つのDataFrame(表)としてまとめることが可能
from glob import globimport pandas ...