0

this is a sample diabetics dataset

I want to get only the 2 mentioned columns as the output but i am not sure about the code for that

df.get("gender", "heart_disease")

I tried this and the code is working but I am only getting the output of gender want only 10 sample outputs. how do i get that?

  • Does this answer your question? [Pandas: Setting no. of max rows](https://stackoverflow.com/questions/16424493/pandas-setting-no-of-max-rows) – mkrieger1 Jul 01 '23 at 15:05

2 Answers2

0

First, subset the pandas data frame using the df[list of columns] notation then sample

df[['gender', 'heart_disease']].sample(10)
BushMinusZero
  • 1,202
  • 16
  • 21
  • i am trying to plot a graph for the same 2 columns and i used this code - plt.figure(figsize = (3,3)) df[["gender", "heart_disease"]].plot(kind = "bar") plt.xlabel("heart_disease") plt.ylabel("gender"); This is Throwing an error, what is the right code for this? – Girish bhagwanani Jul 01 '23 at 15:30
  • pls help with the above comment – Girish bhagwanani Jul 01 '23 at 15:37
0

You can use this code

df[["gender", "heart_disease"]]