问题
New to Pandas and fairly new to Python. I’m trying to produce a crosstabs report from the following data – just showing a few rows.
PALLET_ID AISLE NUM_PALLETS
7197033 AH 1
7197035 AC 1
7197035 AC 1
7197035 AC 1
7197035 AC 1
7197035 AC 1
I Sofastats I get a simple crosstab table of frequency of pallets within aisles - I.e. pallets down the left and aisles along the top. (New Stackoverflow account doesn't allow images).
I am trying to do this in Pandas.
import pandas as pd
import numpy as np
dataF = pd.DataFrame(pd.read_csv('S:\misc\multistorepick\mstorepick2.csv'))
dataF
Out[8]:
<class 'pandas.core.frame.DataFrame'>
Int64Index: 915 entries, 0 to 914
Data columns (total 3 columns):
PALLET_ID 915 non-null values
AISLE 915 non-null values
NUM_PALLETS 915 non-null values
dtypes: int64(2), object(1)
Then following the handedness by gender example in the Python for Data Analysis book
Xtab = pd.crosstab(dataF.PALLET_ID,dataF.AISLE,margins=True)
Xtab
Out[11]:
<class 'pandas.core.frame.DataFrame'>
Index: 78 entries, 7197033 to All
Data columns (total 13 columns):
AA 78 non-null values
AB 78 non-null values
AC 78 non-null values
AD 78 non-null values
AE 78 non-null values
AF 78 non-null values
AG 78 non-null values
AH 78 non-null values
AJ 78 non-null values
AK 78 non-null values
AL 78 non-null values
BG 78 non-null values
All 78 non-null values
dtypes: int64(13)
I’m doing something very dumb. Can someone please tell me what it is?
来源:https://stackoverflow.com/questions/22351001/python-pandas-crosstabs