小编Rod*_*gas的帖子

ValueError:无法将字符串转换为float:id

我正在运行以下python脚本:

#!/usr/bin/python

import os,sys
from scipy import stats
import numpy as np

f=open('data2.txt', 'r').readlines()
N=len(f)-1
for i in range(0,N):
    w=f[i].split()
    l1=w[1:8]
    l2=w[8:15]
    list1=[float(x) for x in l1]
    list2=[float(x) for x in l2]
    result=stats.ttest_ind(list1,list2)
    print result[1]
Run Code Online (Sandbox Code Playgroud)

但是我得到的错误如下:

ValueError: could not convert string to float: id
Run Code Online (Sandbox Code Playgroud)

我很困惑.当我在交互式部分中只尝试一行时,而不是使用脚本循环:

>>> from scipy import stats
>>> import numpy as np
>>> f=open('data2.txt','r').readlines()
>>> w=f[1].split()
>>> l1=w[1:8]
>>> l2=w[8:15]
>>> list1=[float(x) for x in l1]
>>> list1
[5.3209183842, 4.6422726719, 4.3788135547, 5.9299061614, 5.9331108706, 5.0287087832, 4.57...]
Run Code Online (Sandbox Code Playgroud)

我运作良好.

任何人都可以解释一下吗?谢谢

python string floating-point

61
推荐指数
7
解决办法
59万
查看次数

AttributeError:“系列”对象没有属性“has_z”

GeoDataFrame我从 CSV 文件中获取了以下内容,并经过一些切片CRSgeometry分配

    ctf_nom         geometry                                    id      
0   Prunus mahaleb  POINT (429125.795043319 4579664.7564311)    2616    
1   Betula pendula  POINT (425079.292045901 4585098.09043407)   940     
2   Betula pendula  POINT (425088.115045896 4585093.66943407)   940     
3   Abelia triflora POINT (429116.661043325 4579685.93743111)   2002    
4   Abies alba      POINT (428219.962044021 4587346.66843531)   797  
Run Code Online (Sandbox Code Playgroud)

我已经将 a 转换geometrystr

from shapely import wkt

df['geometry'] = df['geometry'].apply(wkt.loads)
df_geo = gpd.GeoDataFrame(df, geometry = 'geometry')
Run Code Online (Sandbox Code Playgroud)

并通过以下方式分配了一个crs:

df_geo.crs = {'init' :'epsg:25831'}
df_geo.crs
Run Code Online (Sandbox Code Playgroud)

当我尝试再次按 gdf.to_file()函数保存减少的地理数据帧时,它返回以下属性错误:

AttributeError: 'Series' object has no …

attributeerror python-3.x writetofile geopandas

5
推荐指数
1
解决办法
1461
查看次数

turn "string-like" list into int with python

After after retrieving some data, some rows of my dataframe are composed by "string-like" lists, like this one:

       bar                foo
   0     'A'                1
   1     'B'                2
   2     'B'     "['2' ,'3']"
   3     'B'              '4'
   4     'C'     "['5' ,'3']"
Run Code Online (Sandbox Code Playgroud)

How could I turn the foo column into int values and take the bigger value with python pandas?

python pandas

5
推荐指数
1
解决办法
69
查看次数

Geopandas 空间连接 - AttributeError: 'NoneType' 对象没有属性 'bounds'

我有以下地理数据框,对应于常规网格:

        id   grid_id    geometry
0       48         0    (POLYGON ((2.052457758079306 41.42493869117656...
1       49         1    (POLYGON ((2.052470852112577 41.42403805731954...
2       215        2    (POLYGON ((2.053641274433816 41.42584917461342...
3       216        3    (POLYGON ((2.053654352531821 41.42494854059127...
4       217        4    (POLYGON ((2.053667430035439 41.42404790642426...
Run Code Online (Sandbox Code Playgroud)

和一个点地理数据框:

    id_act  geometry
0   4001    POINT (2.183026563657264 41.37459702541483)
1   4003    POINT (2.183012216695291 41.37471411724238)
2   4003    POINT (2.183128113845906 41.37472901746361)
3   3002    POINT (2.182820482338962 41.37482095671629)
4   4003    POINT (2.182945418252172 41.37482221760939)
Run Code Online (Sandbox Code Playgroud)

我正在通过空间连接合并两个数据框:

id_grid = gpd.sjoin(gdf, grid, how="inner", op='intersects')
Run Code Online (Sandbox Code Playgroud)

但它返回以下内容AttributeError

AttributeError: 'NoneType' object has no attribute 'bounds'
Run Code Online (Sandbox Code Playgroud)

关键是当我调用函数时: …

bounds python-3.x geopandas

2
推荐指数
1
解决办法
4886
查看次数