我确定我犯了一个明显的错误,但看不到它。
我的df看起来像这样:
id year plan grade prior_grade
21 2017 text A B
56 2015 text B B
43 2016 text A C
并且想要创建一个新的df,只包含那些previous_grade = c的行。我正在使用它来这样做:
prior_c = (df.loc[(df['prior_grade']=='C')])
返回一个空的df(列名称打印但在调用prior_c.head()
时没有行)
再一次,我确定我犯了一个明显的错误,但却看不到它。
编辑:尝试用少量的parens并得到相同的结果:
prior_c = df.loc[df['prior_grade']=='C']
答案 0 :(得分:0)
这应该可行,但我相信你应该复制数据帧。这用于明确地使新数据帧成为副本(而不是原始视图),以避免无意中更改原始df。我建议如下:
<body style="background-color: White">
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<div>
<ul class="topnav">
<li>
<img src="https://cync.cinergycinemas.com/Images/Logo-15.png" alt="Logo" />
</li>
<li><a href="Adminhome.aspx">Home</a></li>
<li>
<a class="active" href="timecontrol.aspx">Employees<br />
<asp:Label ID="lbltotalemp" runat="server" Font-Bold="True"></asp:Label>
</a>
</li>
<li>
<a href="clockedIN.aspx">Clocked IN<br />
<asp:Label ID="lblin" runat="server" Font-Bold="True"></asp:Label>
</a>
</li>
<li>
<a href="Overtimegv.aspx">Overtime<br />
<asp:Label ID="lblot" runat="server" Font-Bold="True"></asp:Label>
</a>
</li>
<li class="right"><a href="EID2.aspx">Sign out</a></li>
</ul>
</div>
<%-- Search box autocomplete extender using ajax --%>
<br />
<br />
<br />
<div style="margin: 50px; text-align: center">
<asp:TextBox ID="txtSearch" runat="server"></asp:TextBox>
<ajaxToolkit:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server"
ServiceMethod="SearchCustomers"
MinimumPrefixLength="1"
CompletionInterval="100" EnableCaching="false" CompletionSetCount="0"
TargetControlID="txtSearch"
FirstRowSelected="True"
CompletionListCssClass="AutoExtender"
CompletionListItemCssClass="AutoExtenderList"
CompletionListHighlightedItemCssClass="AutoExtenderHighlight"
CompletionListElementID="divwidth">
</ajaxToolkit:AutoCompleteExtender>
<asp:Button ID="btnSearch" runat="server" Text="Search" /><br />
<br />
<%-- <input type="checkbox" id="Virtual_Keyboard" />Use Virtual Keyboard<br />--%>
<%-- Gridview 1--%>
<asp:GridView ID="MainGV" runat="server" AutoGenerateColumns="False" CssClass="mGrid" PagerStyle-CssClass="pgr" AlternatingRowStyle-CssClass="alt" DataKeyNames="EID" HorizontalAlign="Center" EmptyDataText="No Data Found. Try Again !" AllowPaging="True" Font-Bold="True" ForeColor="Black" AllowSorting="True" OnRowDataBound="MainGV_RowDataBound">
<AlternatingRowStyle CssClass="alt"></AlternatingRowStyle>
<Columns>
<asp:TemplateField><%--Plus and minus buttons--%>
<ItemTemplate>
<img src="images/plus.png" style="cursor: pointer" />
<asp:Panel ID="Panel1" runat="server" Style="display: none">
<%--Style="display: none"--%>
<asp:GridView ID="childGV" runat="server" AutoGenerateColumns="False" CssClass="mGrid" PagerStyle-CssClass="pgr" AlternatingRowStyle-CssClass="alt" DataKeyNames="EID" HorizontalAlign="Center" EmptyDataText="No Data / Approved !" AllowPaging="True" Font-Bold="True" ForeColor="Black">
<AlternatingRowStyle CssClass="alt" />
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<asp:CheckBox runat="server" ID="chkCheckall" onclick="checkAll(this)" AutoPostBack="True"></asp:CheckBox>
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox runat="server" ID="chkCheck" onclick="Check_Click(this)" AutoPostBack="True" OnCheckedChanged="chkCheck_CheckedChanged"></asp:CheckBox>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="ID" HeaderText="ID" ReadOnly="True" InsertVisible="False" SortExpression="ID" Visible="false"></asp:BoundField>
<asp:BoundField DataField="EID" HeaderText="EID" ReadOnly="True" SortExpression="EID" Visible="false"></asp:BoundField>
<asp:BoundField DataField="FirstName" HeaderText="FirstName" SortExpression="FirstName" Visible="false"></asp:BoundField>
<asp:BoundField DataField="LastName" HeaderText="LastName" SortExpression="LastName" Visible="false"></asp:BoundField>
<asp:BoundField DataField="Gender" HeaderText="Gender" SortExpression="Gender" Visible="false"></asp:BoundField>
<asp:BoundField DataField="Department" HeaderText="Department" SortExpression="Department" Visible="false"></asp:BoundField>
<asp:BoundField DataField="JobFunctionalTitle" HeaderText="JobFunctionalTitle" SortExpression="JobFunctionalTitle" Visible="false"></asp:BoundField>
<asp:BoundField DataField="IN_Time" HeaderText="IN_Time" ReadOnly="True" SortExpression="IN_Time"></asp:BoundField>
<asp:BoundField DataField="OUT_Time" HeaderText="OUT_Time" ReadOnly="True" SortExpression="OUT_Time"></asp:BoundField>
<asp:BoundField DataField="Department1" HeaderText="Department1" SortExpression="Department1"></asp:BoundField>
<asp:BoundField DataField="Hours2" HeaderText="Hours2" SortExpression="Hours2"></asp:BoundField>
<asp:BoundField DataField="Notes" HeaderText="Notes" SortExpression="Notes"></asp:BoundField>
</Columns>
<PagerStyle CssClass="pgr" />
</asp:GridView>
</asp:Panel>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="EID" SortExpression="EID">
<%--<EditItemTemplate>
<asp:Label runat="server" Text='<%# Eval("EID") %>' ID="Label1"></asp:Label>
</EditItemTemplate>--%>
<ItemTemplate>
<asp:Label runat="server" Text='<%# Bind("EID") %>' ID="Label1"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="FullName" SortExpression="FullName">
<EditItemTemplate>
<asp:Label runat="server" Text='<%# Eval("FullName") %>' ID="Label2"></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label runat="server" Text='<%# Bind("FullName") %>' ID="Label2"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Gender" SortExpression="Gender">
<EditItemTemplate>
<asp:TextBox runat="server" Text='<%# Bind("Gender") %>' ID="TextBox1"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label runat="server" Text='<%# Bind("Gender") %>' ID="Label3"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Department" SortExpression="Department">
<EditItemTemplate>
<asp:TextBox runat="server" Text='<%# Bind("Department") %>' ID="TextBox2"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label runat="server" Text='<%# Bind("Department") %>' ID="Label4"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="JobFunctionalTitle" SortExpression="JobFunctionalTitle">
<EditItemTemplate>
<asp:TextBox runat="server" Text='<%# Bind("JobFunctionalTitle") %>' ID="TextBox3"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label runat="server" Text='<%# Bind("JobFunctionalTitle") %>' ID="Label5"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Location" SortExpression="Location">
<EditItemTemplate>
<asp:TextBox runat="server" Text='<%# Bind("Location") %>' ID="TextBox4"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label runat="server" Text='<%# Bind("Location") %>' ID="Label6"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Location_Name" SortExpression="Location_Name" Visible="false">
<EditItemTemplate>
<asp:TextBox runat="server" Text='<%# Bind("Location_Name") %>' ID="TextBox5"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label runat="server" Text='<%# Bind("Location_Name") %>' ID="Label7"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<PagerStyle CssClass="pgr"></PagerStyle>
</asp:GridView>
</div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:dev_prashanthConnectionString %>" SelectCommand="Sp_timedeptdisplaytest1" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:ControlParameter ControlID="HFLocnum" Name="Locnum" PropertyName="Value" Type="String" DefaultValue=""></asp:ControlParameter>
<asp:ControlParameter ControlID="txtSearch" PropertyName="Text" DefaultValue="NULL" Name="SearchText" Type="String"></asp:ControlParameter>
</SelectParameters>
</asp:SqlDataSource>
<%--<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString='<%$ ConnectionStrings:DWHConnectionString %>' SelectCommand="SELECT * FROM [tbl_EID_PIN]"></asp:SqlDataSource>--%>
<asp:HiddenField ID="HFclkincount" runat="server" />
<asp:HiddenField ID="HFtotalcount" runat="server" />
<asp:HiddenField ID="HFLocnum" runat="server" />
<asp:HiddenField ID="HFhours2" runat="server" />
<script>
function CreatePopup() {
return confirm("Do you confirm?");
}
</script>
<asp:HiddenField ID="HFEID" runat="server" />
</form>
</body>