Tag: 大块的

在pandas 0.10.1上使用pandas.read_csv指定dtype float32

我试图用pandas read_csv方法读取一个简单的空格分隔的文件。 不过,pandas似乎并不服从我的dtype论点。 也许我不正确地指定它? 我将这个简单的testing用例简化为read_csv 。 我实际上在我的“真实”场景中使用了converters参数,但为了简单起见,我将其删除了。 以下是我的ipython会话: >>> cat test.out ab 0.76398 0.81394 0.32136 0.91063 >>> import pandas >>> import numpy >>> x = pandas.read_csv('test.out', dtype={'a': numpy.float32}, delim_whitespace=True) >>> x ab 0 0.76398 0.81394 1 0.32136 0.91063 >>> xadtype dtype('float64') 我也尝试过使用numpy.int32或numpy.int64 。 这些select导致一个例外: AttributeError: 'NoneType' object has no attribute 'dtype' 我假设AttributeError是因为pandas不会自动尝试转换/截断浮点值为一个整数? 我正在32位机器上运行一个32位版本的Python。 >>> !uname […]

从Numpy数组创build一个Pandas DataFrame:如何指定索引列和列标题?

我有一个由列表列表组成的Numpy数组,表示一个具有行标签和列名称的二维数组,如下所示: data = array([['','Col1','Col2'],['Row1',1,2],['Row2',3,4]]) 我希望得到的DataFrame有Row1和Row2作为索引值,Col1,Col2作为标题值 我可以指定如下索引: df = pd.DataFrame(data,index=data[:,0]), 但是我不确定如何最好地分配列标题。