2021-08-25

A value is trying to be set on a copy of a slice from a DataFrame.Try using .loc[row_indexer,col_indexer] = value instead

df2[df2['是否滞销']==1][df2['滞销比例%']<1]['滞销比例%'] = df2[df2['是否滞销']==1][df2['滞销比例%']<1]['滞销比例%']*100

在运行上方代码的时候,出现了警告 通过阅读提示的官方文档,发现是DataFrame使用方法的错误导致了更差的使用效果。

官方文档对示例的解释如下:

These both yield the same results, so which should you use? It is instructive to understand the order of operations on these and why method 2 (.loc) is much preferred over method 1 (chained []).

dfmi[‘one’] selects the first level of the columns and returns a DataFrame that is singly-indexed. Then another Python operation dfmi_with_one[‘second’] selects the series indexed by ‘second’. This is indicated by the variable dfmi_with_one because pandas sees these operations as separate events. e.g. separate calls to getitem, so it has to treat them as linear operations, they happen one after another.

Contrast this to df.loc[ : ,(‘one’,‘second’)] which passes a nested tuple of (slice(None),(‘one’,‘second’)) to a single call to getitem. This allows pandas to deal with this as a single entity. Furthermore this order of operations can be significantly faster, and allows one to index both axes if so desired.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是将XML转换为.NET Core实体模型的代码示例: ```csharp using System.Xml.Serialization; [XmlRoot(ElementName = "OTA_InventoryCheckRS")] public class InventoryCheckResponse { [XmlAttribute(AttributeName = "TimeStamp")] public string TimeStamp { get; set; } [XmlAttribute(AttributeName = "Version")] public string Version { get; set; } [XmlAttribute(AttributeName = "EchoToken")] public string EchoToken { get; set; } [XmlElement(ElementName = "HotelResult")] public HotelResult HotelResult { get; set; } } public class HotelResult { [XmlElement(ElementName = "HotelID")] public string HotelID { get; set; } [XmlElement(ElementName = "HotelProducts")] public HotelProducts HotelProducts { get; set; } } public class HotelProducts { [XmlElement(ElementName = "HotelProduct")] public HotelProduct HotelProduct { get; set; } } public class HotelProduct { [XmlElement(ElementName = "FreeCancelable")] public FreeCancelable FreeCancelable { get; set; } [XmlElement(ElementName = "RoomTypes")] public RoomTypes RoomTypes { get; set; } [XmlElement(ElementName = "RatePlans")] public RatePlans RatePlans { get; set; } [XmlElement(ElementName = "Prices")] public Prices Prices { get; set; } } public class FreeCancelable { [XmlAttribute(AttributeName = "FreeCancelableVal")] public string FreeCancelableVal { get; set; } } public class RoomTypes { [XmlElement(ElementName = "RoomType")] public RoomType RoomType { get; set; } } public class RoomType { [XmlAttribute(AttributeName = "RoomTypeCode")] public string RoomTypeCode { get; set; } } public class RatePlans { [XmlElement(ElementName = "RatePlan")] public RatePlan RatePlan { get; set; } } public class RatePlan { [XmlAttribute(AttributeName = "RatePlanCode")] public string RatePlanCode { get; set; } } public class Prices { [XmlElement(ElementName = "Price")] public Price Price { get; set; } } public class Price { [XmlElement(ElementName = "Base")] public Base Base { get; set; } } public class Base { [XmlAttribute(AttributeName = "EffectDate")] public string EffectDate { get; set; } [XmlAttribute(AttributeName = "SalePrice")] public string SalePrice { get; set; } [XmlAttribute(AttributeName = "BasePrice")] public string BasePrice { get; set; } [XmlAttribute(AttributeName = "Allotment")] public string Allotment { get; set; } [XmlAttribute(AttributeName = "DcOverSaleAllotment")] public string DcOverSaleAllotment { get; set; } [XmlAttribute(AttributeName = "DcAddAllotment")] public string DcAddAllotment { get; set; } [XmlAttribute(AttributeName = "DcContractAllotment")] public string DcContractAllotment { get; set; } [XmlAttribute(AttributeName = "DcBuyOutAllotment")] public string DcBuyOutAllotment { get; set; } } ``` 在调用方代码中,您可以使用以下代码将XML转换为.NET Core实体模型: ```csharp string xml = "<OTA_InventoryCheckRS TimeStamp=\"1629879848173\" Version=\"1.000\" EchoToken=\"18029461-194a-4c7e-b372-6eec346cebd4\"> <HotelResult> <HotelID>10000007</HotelID> <HotelProducts> <HotelProduct> <!--只有支持30分钟免费取消的酒店,才需要返回该节点--> <FreeCancelable FreeCancelableVal=\"true\" /> <RoomTypes> <RoomType RoomTypeCode=\"2106\"/> </RoomTypes> <RatePlans> <RatePlan RatePlanCode=\"302-4529\"/> </RatePlans> <Prices> <Price> <Base EffectDate=\"2021-08-25\" SalePrice=\"515.2\" BasePrice=\"515.2\" Allotment=\"53\" DcOverSaleAllotment=\"53\" DcAddAllotment=\"-1\" DcContractAllotment=\"-1\" DcBuyOutAllotment=\"-1\"/> </Price> </Prices> </HotelProduct> </HotelProducts> </HotelResult> </OTA_InventoryCheckRS>"; XmlSerializer serializer = new XmlSerializer(typeof(InventoryCheckResponse)); using StringReader reader = new StringReader(xml); InventoryCheckResponse response = (InventoryCheckResponse)serializer.Deserialize(reader); ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值