小编JJS*_*ith的帖子

Python Pandas计算特定值的出现次数

我试图找到某个值出现在一列中的次数.

我已经制作了数据帧 data = pd.DataFrame.from_csv('data/DataSet2.csv')

现在我想找到某个列出现的次数.这是怎么做到的?

我认为这是下面的,我正在查看教育专栏并计算?发生的时间.

下面的代码显示我试图找到9th出现的次数,错误是我运行代码时得到的

missing2 = df.education.value_counts()['9th']
print(missing2)
Run Code Online (Sandbox Code Playgroud)

错误

KeyError: '9th'
Run Code Online (Sandbox Code Playgroud)

python pandas

32
推荐指数
6
解决办法
8万
查看次数

Android XML切断了布局的下半部分

我的XML布局有问题,我认为这不会给我带来很多问题.我在滚动视图中有一个布局,但布局的底部被切断,我看不到第二个列表视图之外的任何内容.从环顾四周看,我似乎无法看到xml本身有什么问题,我看不出我做错了什么.

我已经尝试了对问题的建议,即为每个不同的元素添加权重,但这仍然没有解决问题.

我还添加了可能有助于解决问题的片段所在的主要活动

片段XML

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/coordinatorLayout">
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:fillViewport="true"
    android:scrollbars="vertical">
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical">
        <android.support.design.widget.TextInputLayout
            android:id="@+id/text_input_layout"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1">

            <EditText
                android:id="@+id/editText"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="Recipe Title"/>
        </android.support.design.widget.TextInputLayout>

        <TextView
            android:id="@+id/ingredientsHeading"
            android:layout_below="@+id/text_input_layout"
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:text="Ingredients"
            android:textStyle="bold|italic"
            android:layout_weight="1" />
        <ListView
            android:id="@+id/ingredientsList"
            android:layout_below="@+id/ingredientsHeading"
            android:layout_above="@+id/directionsHeading"
            android:layout_width="wrap_content"
            android:layout_height="195dp"
            android:layout_weight="1"></ListView>

        <Button style="@style/Button"
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:text="Add Ingredient"
            android:id="@+id/addIngredient"
            android:layout_below="@+id/ingredientsList"
            android:enabled="true"
            android:layout_gravity="center_horizontal"
            android:layout_weight="1" />

        <TextView
            android:id="@+id/directionsHeading"
            android:layout_below="@+id/addIngredient"
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:text="Directions"
            android:textStyle="bold|italic"
            android:layout_weight="1" />
        <ListView
            android:id="@+id/directionsList"
            android:layout_below="@+id/directionsHeading"
            android:layout_width="wrap_content"
            android:layout_height="195dp"
            android:layout_weight="1"></ListView> …
Run Code Online (Sandbox Code Playgroud)

android android-layout android-xml android-fragments android-studio

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

熊猫将变量名传递给列名

我有一个包含13个不同列名的数据框,我将这些标题分为两个列表。我现在想对每个列表执行不同的操作。

是否可以将列名作为变量传递到pandas中?目前,我的代码可以在列表中循环,但是我在尝试将列名传递给函数时遇到了麻烦

CONT = ['age','fnlwgt','capital-gain','capital-loss']
#loops through columns
for column_name, column in df.transpose().iterrows():
    if column_name in CONT:
        X = column_name
        print(df.X.count())
    else:
        print('')
Run Code Online (Sandbox Code Playgroud)

python pandas

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

带有复选框的Android ListView删除/获取行ID

我正在尝试使用复选框实现列表视图,以便在选中复选框时,将删除列表行.我用光标填充列表视图,这工作正常,正在显示复选框.

我遇到的问题是弄清楚如何获取已检查的框的行的_id.

任何人都可以告诉我如何实现这样的事情

ListView和CheckBox

        Cursor cursor = db.getAllItems();

    //String[] columns = new String[] {db.KEY_NAME, db.KEY_CODE, db.KEY_ROWID};
    String[] columns = new String[] {db.KEY_ITEM_NAME, db.KEY_MEASUREMENT, db.KEY_UNIT};

    int[] to = new int[] {R.id.ingredientName, R.id.ingredientMeasurement, R.id.ingredientUnit};

    final SimpleCursorAdapter myCursorAdapter = new SimpleCursorAdapter(this,R.layout.row4, cursor, columns, to, 0);

    final ListView shoppingList = (ListView) findViewById(R.id.shoppingList);
    shoppingList.setAdapter(myCursorAdapter);


    CheckBox deleteCheck = (CheckBox)findViewById(R.id.checkBox1);

    deleteCheck.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            if (isChecked){
                // How do I get the list item clicked to delete row?
            }
        } …
Run Code Online (Sandbox Code Playgroud)

checkbox android listview

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

Android在片段内显示Snackbar

我在片段中显示一个快餐栏时遇到了一些问题.我可以为一个活动设置一个好的但是当我尝试一个片段时它就不会出现并且没有给出错误.

片段内的小吃

Snackbar snackbar = Snackbar.make(rootView, "Snackbar test", Snackbar.LENGTH_SHORT);
View sbView = snackbar.getView();
TextView textView = (TextView) sbView.findViewById(android.support.design.R.id.snackbar_text);
textView.setTextColor(Color.YELLOW);
snackbar.show();   
Run Code Online (Sandbox Code Playgroud)

片段中的rootView

    rootView = inflater.inflate(R.layout.fragment_possible_recipes, container, false);
Run Code Online (Sandbox Code Playgroud)

片段XML

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/coordinatorLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">

<ListView
    android:id="@android:id/list"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"></ListView>

<ImageView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:paddingTop="10dp"
    android:paddingBottom="50dp"
    android:src="@drawable/no_result"
    android:visibility="gone"
    android:id="@+id/imageview"
    android:layout_gravity="center"/>

<android.support.design.widget.FloatingActionButton
    android:id="@+id/filterButton"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentEnd="true"
    android:layout_gravity="bottom|right"
    android:layout_marginBottom="63dp"
    android:layout_marginRight="16dp"
    android:clickable="true"
    android:src="@drawable/ic_filter"
    app:backgroundTint="@color/floatingButton" />


 </android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)

主要活动XML

<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- The main content view -->

<android.support.design.widget.CoordinatorLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent" …
Run Code Online (Sandbox Code Playgroud)

xml android android-fragments

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

Android Volley onErrorResponse没有给出错误

我正在尝试使用volley进行用户登录和注册,但在尝试登录或注册时遇到了问题.我尝试连接的服务器在我的localhost上,它已打开并正常工作,我可以从其他应用程序访问它.

当我输入登录/注册的凭据并按下按钮时,我得到一条日志,说明错误消息为空.问题是应用程序没有崩溃,日志猫没有指向导致错误的任何行,所以我不知道真的出了什么问题.

我尝试了不同的齐射错误方法,error.networkResponse以及其他一些尝试获取更多信息,但没有返回任何信息.

我已经在网站上看到了遇到类似问题的人的其他解决方案,但似乎没有任何效果.

任何人都可以向我解释为什么我收到此错误?

记录猫日志

Login Error: null
Run Code Online (Sandbox Code Playgroud)

类打印日志 - LoginActivity

import android.app.Activity;
    import android.app.ProgressDialog;
    import android.content.Intent;
    import android.os.Bundle;
    import android.util.Log;
    import android.view.View;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.Toast;

    import com.android.volley.Request.Method;
    import com.android.volley.Response;
    import com.android.volley.VolleyError;
    import com.android.volley.toolbox.StringRequest;

    import org.json.JSONException;
    import org.json.JSONObject;

    import java.util.HashMap;
    import java.util.Map;

    import com.example.rory.pocketchef.R;
    import com.example.rory.pocketchef.app.AppConfig;
    import com.example.rory.pocketchef.app.AppController;
    import com.example.rory.pocketchef.helper.SQLiteHandler;
    import com.example.rory.pocketchef.helper.SessionManager;

    public class LoginActivity extends Activity {
        private static final String TAG = RegisterActivity.class.getSimpleName();
        private Button btnLogin;
        private Button btnLinkToRegister;
        private EditText inputEmail; …
Run Code Online (Sandbox Code Playgroud)

android android-volley

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