Code Sample, a copy-pastable example if possible
samples = pd.read_csv("https://archive.ics.uci.edu/ml/machine-learning-databases/wine/wine.data", sep=',',header=None)
varieties = pd.DataFrame(samples.iloc[:,0])
kmeans = KMeans(n_clusters = 3)
labels = kmeans.fit_predict(samples)
#setting 'labels' according to given data
labels += 1
#converting 'labels' to pandas DataFrame
labels = pd.DataFrame(labels)
df = pd.DataFrame({'labels':[labels], 'varieties':[varieties]})
ct = pd.crosstab(df['labels'],df['varieties'])
Problem description
My Dataset is like
labels \
0 0 0 2 1 2 2 2 3 2 4 3 5 ...
varieties
0 0 0 1 1 1 2 1 3 1 4 1 5 ...
Expected Output
output from "crosstab" function
Comment From: TomAugspurger
Can you fix your issue report to be copy-passable? Right now labels
and varieties
aren't defined.
See if you can simplify it. Also post the traceback.
Comment From: aashray18521
@TomAugspurger I've updated code as far as I understood your request. Please do let me know
Comment From: TomAugspurger
I don't think your example needs to include scikit-learn or reading CSVs. See https://stackoverflow.com/help/mcve for creating good examples.
That said, you seem to be storing DataFrames inside another DataFrame with df = pd.DataFrame({'labels':[labels], 'varieties':[varieties]})
. You probably don't want to do that.
Comment From: aashray18521
@TomAugspurger I want to use these dataframes (labels and varieties) for 'crosstab' function. Please do let me know how I can do that? scikit-learn is being used by me for other tasks in the remainder of my code
Comment From: TomAugspurger
You might want to ask on stackoverflow. But in general you don't want nested data frames. The columns should just be the arrays themselves.
On Apr 5, 2017, at 12:03, aashray18521 notifications@github.com wrote:
@TomAugspurger I want to use these dataframes (labels and varieties) for 'crosstab' function. Please do let me know how I can do that? scikit-learn is being used by me for other tasks in the remainder of my code
— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.