Home > Net >  How can assign a value to column name and create a variable?
How can assign a value to column name and create a variable?

Time:08-06

Variable column has different values such as: "Municipal waste generated" and "Recycling" then the Value columns provide values for "Municipal waste generated" and "Recycling". How can I have two different variables such as Municipal waste generated and Recycling?

CodePudding user response:

To get all the rows where Variable column is either "Recycling" or "Municipal waste generated", you can use query :

df = # your dataframe
result = df.query('Variable.isin(("Recycling", "Municipal waste generated"))').copy()

result

CodePudding user response:

Check Below code - PIVOT is used enter image description here

  • Related