質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
ソート

複数のデータを、順序性に従って並べ替えること。 データ処理を行う際に頻繁に用いられ、多くのアルゴリズムが存在します。速度、容量、複雑さなどに違いがあり、高速性に特化したものにクイックソートがあります。

関数

関数(ファンクション・メソッド・サブルーチンとも呼ばれる)は、はプログラムのコードの一部であり、ある特定のタスクを処理するように設計されたものです。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Google

Googleは、アメリカ合衆国に位置する、インターネット関連のサービスや製品を提供している企業です。検索エンジンからアプリケーションの提供まで、多岐にわたるサービスを提供しています。

Q&A

解決済

1回答

3379閲覧

DataFrameをエクセルに書き出すことについて

CHutida

総合スコア1

ソート

複数のデータを、順序性に従って並べ替えること。 データ処理を行う際に頻繁に用いられ、多くのアルゴリズムが存在します。速度、容量、複雑さなどに違いがあり、高速性に特化したものにクイックソートがあります。

関数

関数(ファンクション・メソッド・サブルーチンとも呼ばれる)は、はプログラムのコードの一部であり、ある特定のタスクを処理するように設計されたものです。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Google

Googleは、アメリカ合衆国に位置する、インターネット関連のサービスや製品を提供している企業です。検索エンジンからアプリケーションの提供まで、多岐にわたるサービスを提供しています。

0グッド

1クリップ

投稿2020/07/02 10:41

データフレームをエクセルに書き出したいです。

Googleコラボレートリーでやっています。

発生している問題は以下の通りになります。

ValueError Traceback (most recent call last) <ipython-input-109-07904bcd5d51> in main() 43 with pd.ExcelWriter('CH6.xlsx') as writer: ---> 44 estimates.to_excel(writer, float_format="%.3f",index=False,encoding="utf-8-sig",sheet_name='sheet1') 45 estimates2.to_excel(writer, float_format="%.3f",index=False,encoding="utf-8-sig",sheet_name='sheet2') 12 frames ValueError: This sheet is too large! Your sheet size is: 1, 40980 Max sheet size is: 1048576, 16384 During handling of the above exception, another exception occurred: IndexError Traceback (most recent call last) /usr/local/lib/python3.6/dist-packages/openpyxl/writer/workbook.py in get_active_sheet(wb) 59 visible_sheets = [idx for idx, sheet in enumerate(wb._sheets) if sheet.sheet_state == "visible"] 60 if not visible_sheets: ---> 61 raise IndexError("At least one sheet must be visible") 62 63 idx = wb._active_sheet_index IndexError: At least one sheet must be visible

該当のソースコード

#hp_optimization.py from sklearn.feature_extraction.text import TfidfVectorizer from sklearn.linear_model import LogisticRegression from sklearn.metrics import accuracy_score from sklearn.model_selection import train_test_split from sklearn.model_selection import GridSearchCV def main(): x, y = load_dataset('data/amazon_reviews_multilingual_JP_v1_00.tsv', n=5000) x = [clean_html(text, strip=True) for text in x] x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.2, random_state=42) vectorizer = TfidfVectorizer(tokenizer=tokenize) x_train_vec = vectorizer.fit_transform(x_train) x_test_vec = vectorizer.transform(x_test) vocab = vectorizer.get_feature_names() parameters = {"penalty":["l1"],"C":[2,2.5,3,3.5,4,4.5,5]} lr = LogisticRegression(solver='liblinear') clf = GridSearchCV(lr, parameters, cv=5, n_jobs=-1) clf.fit(x_train_vec, y_train) best_clf = clf.best_estimator_ print(clf.best_params_) print('Accuracy(best): {:.4f}'.format(clf.best_score_)) y_pred = best_clf.predict(x_test_vec) score = accuracy_score(y_test, y_pred) print('Accuracy(test): {:.4f}'.format(score)) estimates = pd.DataFrame(clf.best_estimator_.coef_, columns=vocab) estimates2 = pd.DataFrame(clf.best_estimator_.coef_, columns=vocab) estimates_sorted = estimates.sort_values(by=0,axis=1,ascending=False) estimates2_sorted = estimates2.sort_values(by=0,axis=1,ascending=False) print(estimates_sorted.iloc[:,:20]) print(estimates2_sorted.iloc[:,-20:]) with pd.ExcelWriter('CH6.xlsx') as writer: estimates.to_excel(writer, float_format="%.3f",index=False,encoding="utf-8-sig",sheet_name='sheet1') estimates2.to_excel(writer, float_format="%.3f",index=False,encoding="utf-8-sig",sheet_name='sheet2') if __name__ == '__main__': main()

試したこと

上位20単語とその推定値、下位20も然りという感じでソートする作業はできたと思っています。
ただ、それを関数内でエクセルに書き出す作業をしようとした時、
with以降で試してみるとシートについてエラーが出てきました。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

エラーが
ValueError: This sheet is too large! Your sheet size is: 1, 40980 Max sheet size is: 1048576, 16384
ということですので、列が多すぎるのではないでしょうか。転置してみるのはどうですか?

python

1# estimates.to_excel(writer, float_format="%.3f",index=False,encoding="utf-8-sig",sheet_name='sheet1') 2estimates.T.to_excel(writer, float_format="%.3f",index=False,encoding="utf-8-sig",sheet_name='sheet1')

投稿2020/07/02 11:03

yymmt

総合スコア1615

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

CHutida

2020/07/02 13:05

ありがとうございました。解決いたしました。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問