I am trying to create a Crosstab of my data that I pull from an SQL server. On other solutions I see people have provided solutions like below:
df = pd.DataFrame([[1,2,3,4]], columns=['a', 'b', 'v', 'w'])
However I already have a dataframe built out by pulling data from a SQL server, looping and appending each item to a list, then created a DataFrame from the list.
Res = c.execute(cmd)
rows=[]
[rows.append(list(row)) for row in Res]
df= pd.DataFrame.from_records(rows)
df.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 124 entries, 0 to 123
Data columns (total 14 columns):
I try to run the code below and get the ValueError message below.
pd.crosstab([df['Term'], df['ID']], df['Class'], margins = True)]
ValueError: Shape of passed values is (1, 3), indices imply (124, 3).
Any help would be greatly appreciated. Thank you.