how can I plot column A as x-axis and B as y-axis with data only related to C. looking for a graph that looks like density graph.
Asked
Active
Viewed 1,424 times
1
-
`usa = df[df.Country == 'USA']` selects a subset of rows in the dataframe. To select a subset of columns, such as score & profit, try: `usa[['score', 'profit']]`. – DarrylG Jan 30 '22 at 04:47
-
Stackoverflow encourages data (such as your table) to be provided as text rather than an image. This allows responders to more easily post answers using your data. – DarrylG Jan 30 '22 at 04:54
-
got it, I will do that next time! – qhfalice Jan 30 '22 at 06:40
1 Answers
1
If you are having error while extracting specific columns then, it might be because of extra spaces, just try removing extra space.
Here is code:
usa = df[df.Country == 'USA']
usa.columns = usa.columns.to_series().apply(lambda x: x.strip())
usa[['Score', 'Profit']]
For Density Graph, the question is still unclear, but here density plot based on what I have understood
import seaborn as sns
p=sns.kdeplot(usa['Score'], shade=True, color="r")
p=sns.kdeplot(usa['Profit'], shade=True, color="b")

Malvi Patel
- 106
- 1
- 7
-
thank you! for second question, I was wondering if there is any plot that I can choose both x and y axis but still looks similar to the density graph (smooth line, not line graph) – qhfalice Jan 30 '22 at 06:44
-
[Link](https://stackoverflow.com/questions/5283649/plot-smooth-line-with-pyplot) Do have a look at this question, is this what you are looking for – Malvi Patel Jan 31 '22 at 03:59