LoginSignup
6
17

More than 5 years have passed since last update.

Python(Pandas/XlsxWriter)を使ってExcelファイルを操作してみる②

Last updated at Posted at 2016-05-20

今後はExcelファイルを読み込む編。

ついでにCSVファイルを読み込むバージョンも。

ファイルの出力についてはこちら

参照

Excelファイルを読み込む

# import lib
import pandas as pd

# read xlsx file
xlsFile = "hoge.xlsx"
sheetName = "hoge1"
xls_data = pd.read_excel(xlsFile, sheetname=sheetName)
print(xls_data)

CSVを読み込む

# import lib
import pandas as pd

# read csv file
csvFile = "fuga.csv"
csv_data = pd.read_csv(csvFile, encoding='utf-8')
print(csv_data)

おまけ

指定した位置のデータを読み込む

列指定
py
xls_data = pd.read_excel(xlsFile, sheetname="hoge1", parse_cols="A:H")

行指定

xls_data = pd.read_excel(xlsFile, sheetname="hoge1", skiprows=0, skip_footer=5)

行列指定したい場合は両方指定すればいい。A1:H5みたいに指定できればいいけど、それはできなさげ?

6
17
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
17