【问题标题】:Beginner - Convert dataframe to rows of strings初学者 - 将数据框转换为字符串行
【发布时间】:2022-11-04 18:43:22
【问题描述】:

我对python完全陌生。我正在尝试使用 azure.servicebus 模块。 https://pypi.org/project/azure-servicebus/

我生成要传递给服务总线的 json 字符串行。 如果我有 2 行或更多行,它可以工作。如果我只有 1 行,它会将字符串中的每个字符拆分为行。

from ayx import Alteryx
from azure.servicebus import ServiceBusClient, ServiceBusMessage

import os
connstr = "xxxxx"
queue_name = "invoicedk"
df = Alteryx.read("#1")
print(df)

alteryxMessage = df.squeeze()
for specificationRows in alteryxMessage.items:
    with ServiceBusClient.from_connection_string(connstr) as client:
        with client.get_queue_sender(queue_name) as sender:
            # Sending a single message
            single_message = ServiceBusMessage(specificationRows)
            sender.send_messages(single_message)

我从 Alteryx 的输入是这样的: `

JSON
{"SpecificationNumber":"A120000010681","InvoiceGroup":"1000004597","FromCriteria":"2022-07-29","ToCriteria":"2022-09-29","SalesProductName":"Freight as per specification ZERO","Price":"52486.00","SpecificationDate":"2022-11-02","VATIdentity":"ZERO","CurrencyMDM":"EUR","NavisionInstance":"1000000001","SalesService":"","ServiceQuantity":"1","PricePrUnit":"52486.00","LengthRecordID":"1"}

{"SpecificationNumber":"A120000010682","InvoiceGroup":"1000004601","FromCriteria":"2022-06-07","ToCriteria":"2022-09-02","SalesProductName":"Freight as per specification ZERO","Price":"93282.59","SpecificationDate":"2022-11-02","VATIdentity":"ZERO","CurrencyMDM":"EUR","NavisionInstance":"1000000001","SalesService":"","ServiceQuantity":"1","PricePrUnit":"93282.59","LengthRecordID":"1"}

`

我试图计算项目,但如果我只有 1 行,它就会失败。所以不知道该怎么办。 如果计数> 1,那么它可以工作。但

s = df.squeeze() 打印(s.count())

AttributeError: 'numpy.int64' object has no attribute 'count'

【问题讨论】:

    标签: python azureservicebus azure-servicebus-queues alteryx


    【解决方案1】:

    尝试: for colname in df.columns: try: df[colname] = df[colname].astype('str') print(f"{colname} converted") except ValueError: print(f"{colname} failed")

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-16
      • 2022-11-26
      • 2017-09-27
      • 2017-06-08
      相关资源
      最近更新 更多