小编Sum*_*pal的帖子

S3 选择检索 CSV 中的标头

我正在尝试使用以下代码从存储在 S# 存储桶中的 CSV 中获取记录的子集:

s3 = boto3.client('s3')
bucket = bucket
file_name = file

sql_stmt = """SELECT S.* FROM s3object S LIMIT 10"""


req = s3.select_object_content(
    Bucket=bucket,
    Key=file,
    ExpressionType='SQL',
    Expression=sql_stmt,
    InputSerialization = {'CSV': {'FileHeaderInfo': 'USE'}},
    OutputSerialization = {'CSV': {}},
)

records = []
for event in req['Payload']:
    if 'Records' in event:
        records.append(event['Records']['Payload'])
    elif 'Stats' in event:
        stats = event['Stats']['Details']


file_str = ''.join(r.decode('utf-8') for r in records)

select_df = pd.read_csv(StringIO(file_str))
df = pd.DataFrame(select_df)
print(df)
Run Code Online (Sandbox Code Playgroud)

这成功地产生了记录但错过了标题。

我在这里读到S3 Select CSV Headers,S3 …

python csv amazon-s3 export-to-csv boto3

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

使用 Plotly Python 在条形图中生成随机颜色

我正在使用 Plotly for Python 生成一些堆积条形图。由于我有 17 个正在堆叠的对象,因此条形的颜色开始重复,如下图所示。

条形图 在此处输入图片说明

有人能告诉我如何为每个堆栈获得独特的颜色吗?

请找到我的代码以生成下面的条形图:

import plotly
plotly.tools.set_credentials_file(username='xxxxxxxx', 
api_key='********')
dd = []
import plotly.plotly as py
import plotly.graph_objs as go
import numpy as np


for k,v in new_dict.items():

    trace = go.Bar(x = x['unique_days'],
                       y = v,
                       name = k,
                       text=v,
                       textposition = 'auto',
                      )
    dd.append(trace)




layout= go.Layout(
    title= 'Daily Cumulative Spend per campaign',
    hovermode= 'closest',
    autosize= True,
    width =5000,
     barmode='stack',
    xaxis= dict(
        title= 'Date',
        zeroline= False,
        gridwidth= 0,
        showticklabels=True,
        tickangle=-45,
        nticks = 60,
        ticklen = 5 …
Run Code Online (Sandbox Code Playgroud)

python python-3.x plotly

4
推荐指数
1
解决办法
3954
查看次数

elasticsearch 中 field_value_factor 的多个输入

我正在尝试使用 field_value_factor 来衡量文档中的某些字段来制定弹性搜索查询。

{
  "query": {
    "match": {
      "local": true
    },
    "function_score": {
      "functions": [
        {
          "field_value_factor": {
            "field": "title",
            "factor": 1.2,
            "missing": 1
          }
        },
        {
          "gauss": {
            "location": {
              "origin": {
                "lat": 51.5,
                "lon": 0.12
              },
              "offset": "2 Miles",
              "scale": "3 Miles"
            }
          }
        },
        {
          "gauss": {
            "creation_time": {
              "decay": 0.8,
              "offset": "2d",
              "scale": "48d"
            }
          },
          "weight": 2
        }
      ]
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

任何输入,如:

"field_value_factor": {
                             "field": [“title”,"description"],
                             "factor": [1.2,0.8],
                             "missing": [1,0]
                            }
Run Code Online (Sandbox Code Playgroud)

不适用于这两个字段,并且查询检索与第一个相同的文档。

是否可以在“field_value_vector”中输入多个术语?

elasticsearch elasticsearch-dsl

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