完整的工作测试案例
当然,根据您在本地和远程计算机上的内存,您的阵列大小会有所不同.
z1 = numpy.random.rand(300000000,2);
for i in range(1000):
print('*******************************************\n');
direct_output = subprocess.check_output('ssh blah@blah "ls /"', shell=True);
direct_output = 'a'*1200000;
a2 = direct_output*10;
print(len(direct_output));
Run Code Online (Sandbox Code Playgroud)
当前用例
如果它有助于我的用例如下:
我发出数据库查询,然后将结果表存储在远程计算机上.然后我想通过网络传输它们并进行分析.到目前为止,我在python中做了类似下面的事情:
#run a bunch of queries before hand with the results in remote files
....
counter = 0
mergedDataFrame = None
while NotDone:
output = subprocess.check_output('ssh blah@blah cat /data/file%08d'%(counter))
data = pandas.read_csv(...)
#do lots of analysis, append, merge, numpy stuff etc...
mergedDataFrame = pandas.merge(...)
counter += 1
Run Code Online (Sandbox Code Playgroud)
在某些时候,我在check_output命令中收到以下错误:[Errno 12]无法分配内存
背景
感谢以下问题,我想我已经知道出了什么问题.发布了许多解决方案,我试图确定哪些解决方案将避免[Errno 12]无法使用fork/clone分配与子进程实现相关的内存错误.
鉴于以下pandas数据框:
df = pd.DataFrame({'A': ['foo' ] * 3 + ['bar'],
'B': ['w','x']*2,
'C': ['y', 'z', 'a','a'],
'D': rand.randn(4),
})
print df.to_string()
"""
A B C D
0 foo w y 0.06075020
1 foo x z 0.21112476
2 foo w a 0.01652757
3 bar x a 0.17718772
"""
Run Code Online (Sandbox Code Playgroud)
注意没有bar,w组合.执行以下操作时:
pv0 = pandas.pivot_table(df, rows=['A','B'],cols=['C'], aggfunc=numpy.sum)
pv0.ix['bar','x'] #returns result
pv0.ix['bar','w'] #key error though i would like it to return all Nan's
pv0.index #returns
[(bar, x), (foo, w), (foo, x)]
Run Code Online (Sandbox Code Playgroud)
只要在'C'列中至少有一个条目与foo,x的情况一样(它在'C'列中只有'z'的值),它将为其他列值返回NaN' C'不存在于foo,x(例如'a','y')
我想要的是拥有所有多索引组合,即使那些没有所有列值数据的组合.
pv0.index …
Run Code Online (Sandbox Code Playgroud) 我经常使用vi命令
:set number
Run Code Online (Sandbox Code Playgroud)
我最近试图将一些基于零的索引的数据与vim中的行号对齐,后者具有基于1的索引.有没有办法让vi从0开始编号,或者更广泛地从任何其他起点编号?
我已经查看了许多出现此错误的问题.我正在跑熊猫'0.10.1'
df = DataFrame({'A' : np.random.randn(5),
'B' : np.random.randn(5),'C' : np.random.randn(5),
'D':['a','b','c','d','e'] })
#gives error
df.take([2,0,1,2,3], axis=1).drop(['C'],axis=1)
#works fine
df.take([2,0,1,2,1], axis=1).drop(['C'],axis=1)
Run Code Online (Sandbox Code Playgroud)
我只能看到,在前一种情况下,我有非数字列,它似乎以某种方式影响索引但是下面的命令返回空:
df.take([2,0,1,2,3], axis=1).index.get_duplicates()
Run Code Online (Sandbox Code Playgroud)
重新索引错误没有任何意义似乎不适用,因为我的旧索引是唯一的.
据我所知,使用此命令df.take([2,0,1,2,3],axis = 1).index.get_duplicates()可以判断我的索引是唯一的:重新索引数据帧的问题:仅重新编制索引对于唯一值的Index对象有效
"重新索引仅对具有唯一值的索引对象有效"似乎不适用
我认为我的pandas版本#是正常的,所以这应该是bug应该不是问题pandas重新索引只对有唯一值的Index对象有效
python ×3
pandas ×2
editor ×1
memory ×1
networking ×1
paramiko ×1
pivot-table ×1
subprocess ×1
vi ×1