Skip to content

Instantly share code, notes, and snippets.

View xuwenhao's full-sized avatar
🎯
Focusing

Xu Wenhao xuwenhao

🎯
Focusing
View GitHub Profile
@davidlenz
davidlenz / 20_newsgroup_to_csv.py
Last active March 4, 2023 15:09
20 newsgroup dataset from sklearn to csv.
from sklearn.datasets import fetch_20newsgroups
import pandas as pd
def twenty_newsgroup_to_csv():
newsgroups_train = fetch_20newsgroups(subset='train', remove=('headers', 'footers', 'quotes'))
df = pd.DataFrame([newsgroups_train.data, newsgroups_train.target.tolist()]).T
df.columns = ['text', 'target']
targets = pd.DataFrame( newsgroups_train.target_names)