显示熊猫列-宽到长

时间:2019-07-02 16:39:55

标签: python pandas python-2.7

假设我在Pandas Dataframe中有一排列标题和相关值:

@Override
public void onItemClick(int item) {

    Intent categoryIntent = new Intent(MainActivity.this, 
    CategoryActivity.class);
    categoryIntent.putExtra("name", foodAdapter.getFood(item));
    startActivity(categoryIntent);
}

我如何像下面这样显示它们:

Intent intent = getIntent();
Food food = intent.getParcelableExtra("name");
category = food.getFoodName();
setTitle(category);

foodViewModel = ViewModelProviders.of(this).get(FoodViewModel.class);
foodViewModel.getFoodCategory(category).observe(this, new 
Observer<List<FoodCategory>>() {
        @Override
        public void onChanged(List<FoodCategory> foodCategories) {
            if (!foodCategories.isEmpty()) {

                progressBar.setVisibility(View.GONE);
                categoryAdapter = new 
CategoryAdapter(CategoryActivity.this, foodCategories);
                recyclerView.setAdapter(categoryAdapter);

                Log.e(TAG, "Category Name: " + category);
            }else {
                Toast.makeText(CategoryActivity.this, "empty list", 
Toast.LENGTH_SHORT).show();
    }
   }
});

2 个答案:

答案 0 :(得分:2)

自定义功能

def new_repr(self):
    g = self.groupby(np.arange(self.shape[1]) // 5, axis=1)
    return '\n\n'.join([d.to_string() for _, d in g])

print(new_repr(df))

   A  B  C  D  E
0  1  2  3  4  5

   F  G  H  I   J
0  6  7  8  9  10

    K
0  11

答案 1 :(得分:2)

pd.set_option('display.width', 20)
pd.set_option('display.expand_frame_repr', True)
 df
   A  B  C  D  E  \
0  1  2  3  4  5   

   F  G  H  I   J  \
0  6  7  8  9  10   

    K  
0  11