Python Pandas Crosstabs

大城市里の小女人 提交于 2019-12-25 02:48:12

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!