小编Avi*_*Raj的帖子

正则表达式排除R中的单词

我真的不知道如何在R中使用不匹配的正则表达式正确地找到单词

例如:数据包括:

x =  c("hail", "small hail", "wind hail",  "deep hail",  "thunderstorm hail", "tstm wind hail", "gusty wind hail", "late season hail", "non severe hail", "marine hail")
Run Code Online (Sandbox Code Playgroud)

我想找到所有有"冰雹"但没有"海洋"的人

我的尝试:

x[grep("[^(marine)] hail", x)]
Run Code Online (Sandbox Code Playgroud)

- >我只有5:

"small hail"      "wind hail"       "deep hail"       "tstm wind hail"  "gusty wind hail"
Run Code Online (Sandbox Code Playgroud)

我不知道其他4会发生什么

regex r

9
推荐指数
3
解决办法
1万
查看次数

如何针对Google Cloud SQL运行Django管理命令

目前,我已经在谷歌应用引擎上部署了我的django项目.我需要运行python manage.py migrate命令,以便auth_user在我的google云实例上创建表.但是不知道在哪里运行这个命令.

python django google-app-engine google-cloud-sql

9
推荐指数
1
解决办法
1826
查看次数

如何使用xml sax解析器读写大型xml?

我正在尝试使用SAX解析器project1从下面的示例xml文档(原始文档大约30 GB)中删除所有节点(以及它们的子元素).如果有一个单独的修改文件或者可以使用in-行编辑.

sample.xml

<ROOT>
    <test src="http://dfs.com">Hi</test>
    <project1>This is old data<foo></foo></project1>
    <bar>
        <project1>ty</project1>
        <foo></foo>
    </bar>
</ROOT>
Run Code Online (Sandbox Code Playgroud)

这是我的尝试..

parser.py

from xml.sax.handler import ContentHandler
import xml.sax

class MyHandler(xml.sax.handler.ContentHandler):
    def __init__(self, out_file):
        self._charBuffer = []
        self._result = []
        self._out = open(out_file, 'w')

    def _createElement(self, name, attrs):
        attributes = attrs.items()
        if attributes:
            out = ''
            for key, value in attributes:
                out += ' {}={}'.format(key, value)
            return '<{}{}>'.format(name, out)
        return '<{}>'.format(name)


    def _getCharacterData(self):
        data = ''.join(self._charBuffer).strip()
        self._charBuffer = []
        self._out.write(data.strip()) #remove strip() …
Run Code Online (Sandbox Code Playgroud)

python xml sax saxparser

9
推荐指数
1
解决办法
5883
查看次数

appcfg.py显示您必须以管理员身份登录

当我尝试将示例csv数据上传到我的GAE应用程序时appcfg.py,它会显示以下401错误.

2015-11-04 10:44:41,820 INFO client.py:571 Refreshing due to a 401 (attempt 2/2) 
2015-11-04 10:44:41,821 INFO client.py:797 Refreshing access_token 

Error 401: --- begin server output ---
You must be logged in as an administrator to access this.
--- end server output ---
Run Code Online (Sandbox Code Playgroud)

这是我试过的命令,

appcfg.py upload_data --application=dev~app --url=http://localhost:8080/_ah/remote_api --filename=data/sample.csv
Run Code Online (Sandbox Code Playgroud)

python google-app-engine

8
推荐指数
1
解决办法
1600
查看次数

Pandas to_sql为ValueError提供了时区感知列

我想使用pandas to_sql在postgresql中存储一个时区感知列.

当时间不是时区感知时,它可以工作

times = ['201510100222', '201510110333']
df = pd.DataFrame()
df['time'] = pd.to_datetime(times)
df.time.to_sql('test', engine, if_exists='replace', index=False)
Run Code Online (Sandbox Code Playgroud)

但是当我指定UTC时

times = ['201510100222', '201510110333']
df = pd.DataFrame()
df['time'] = pd.to_datetime(times, utc=True)
df.time.to_sql('test', engine, if_exists='replace', index=False)
Run Code Online (Sandbox Code Playgroud)

我有以下错误:

ValueError: Cannot cast DatetimeIndex to dtype datetime64[us]
Run Code Online (Sandbox Code Playgroud)

我使用的是python 3.4.3,postgresql 9.4,pandas 0.17.1,sqlalchemy 1.0.5

python postgresql sqlalchemy pandas

8
推荐指数
2
解决办法
4317
查看次数

React Native activeTintColor未应用于所选抽屉项目

React Native activeTintColor未应用于所选抽屉项目.我的反应原生导航路线看起来像,

-> DrawerNavigator
   -> StackNavigator
      -> HomeScreen
      -> FirstScreen
      -> SecondScreen
      -> ThirdScreen
Run Code Online (Sandbox Code Playgroud)

routes.js

const RootStack = createStackNavigator(
  {
    Home: { screen: HomeScreen },
    ChapterGroup: { screen: ChapterGroupScreen },
    Chapter: { screen: ChapterScreen },
  }

const DrawerStack = createDrawerNavigator(
  {
    Home: {
      screen: RootStack,
      params: { id: 1 }
    },
    Kural: { screen: ChapterGroupScreen, params: { id: 2 } },
    Detail: { screen: ChapterGroupScreen, params: { id: 3 } }
  }, { contentComponent: DrawerComponent}
}
export default DrawerStack; …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs react-native

8
推荐指数
1
解决办法
500
查看次数

与R中的区域设置混淆

刚才我回答了在R问题中的EURO符号后删除字符.但是对于我来说,r代码适用于Ubuntu上的其他人.

这是我的代码.

x <- "services as defined in this SOW at a price of € 15,896.80 (if executed fro"
euro <- "\u20AC"
gsub(paste(euro , "(\\S+)|."), "\\1", x)
# "" 
Run Code Online (Sandbox Code Playgroud)

我认为这都是关于更改区域设置,我不知道该怎么做.

我在Windows 8上运行rstudio.

> sessionInfo()
R version 3.2.0 (2015-04-16)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 8 x64 (build 9200)

locale:
[1] LC_COLLATE=English_United States.1252 
[2] LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods  
[7] base     

loaded …
Run Code Online (Sandbox Code Playgroud)

regex r

7
推荐指数
1
解决办法
162
查看次数

根据一组单词拆分字符串

我有一个像这样的字符串列表,

['happy_feet', 'happy_hats_for_cats', 'sad_fox_or_mad_banana','sad_pandas_and_happy_cats_for_people'] 
Run Code Online (Sandbox Code Playgroud)

给定一个关键字列表,['for', 'or', 'and']我希望能够将列表解析为另一个列表,如果关键字列表出现在字符串中,则将该字符串拆分为多个部分.

例如,上面的集合将被拆分为

['happy_feet', 'happy_hats',  'cats', 'sad_fox', 'mad_banana', 'sad_pandas', 'happy_cats', 'people']
Run Code Online (Sandbox Code Playgroud)

目前我已经通过下划线拆分每个内部字符串,并且有一个for循环查找关键字的索引,然后通过下划线重新组合字符串.有更快的方法吗?

python regex string

7
推荐指数
3
解决办法
116
查看次数

gcloud app deploy:此部署包含太多文件

当我尝试通过gcloud部署我的GAE应用程序时,我收到了以下错误.

Updating service [default]...failed.                                                                  
ERROR: (gcloud.app.deploy) Error Response: [400] This deployment has too many files. New versions are limited to 10000 files for this app.

Details: [
  [
    {
      "@type": "type.googleapis.com/google.rpc.BadRequest",
      "fieldViolations": [
        {
          "description": "This deployment has too many files. New versions are limited to 10000 files for this app.",
          "field": "version.deployment.files[...]"
        }
      ]
    }
  ]
]
Run Code Online (Sandbox Code Playgroud)

有没有办法解决这个问题?

python google-app-engine flask

7
推荐指数
2
解决办法
5889
查看次数

SAWarning:当前不支持在执行阶段使用“Session.add()”操作

在特定表上发生插入后,我正在尝试执行一些操作。

user = ModelFactory.create_user(username, email, password)
db.session.add(user)
db.session.commit()
Run Code Online (Sandbox Code Playgroud)

所以我创建了一个自动调用的方法 after_insert

def notify_user(user):
    print user.id
    book = Book(author=user.id, name='foo')
    db.session.add(book)
    db.session.commit(book)

@event.listens_for(User, 'after_insert')
def receive_after_insert(mapper, connection, target):
    print target
    notify_user(target)
Run Code Online (Sandbox Code Playgroud)

但是这段代码显示了一个警告,例如,

SAWarning: Usage of the 'Session.add()' operation is not currently supported within the execution stage of the flush process. Results may not be consistent.  Consider using alternative event listeners or connection-level operations instead.
  % method)

/home/avinash/.virtualenvs/s2s/local/lib/python2.7/site-packages/sqlalchemy/util/langhelpers.py:68: SAWarning: An exception has occurred during handling of a previous exception.  The previous exception …
Run Code Online (Sandbox Code Playgroud)

python sqlalchemy flask-sqlalchemy

7
推荐指数
1
解决办法
2733
查看次数