Page 98 - Informatics_Practices_Fliipbook_Class12
P. 98

Ans.  a. Sales=pd.concat([Sales, Sales2], axis=1)
                print(Sales)
              b.  Sales = Sales.T
              c.  print(Sales[2017])
              d.  print(Sales.loc[['Madhu','Ankit'], [2017,2018]])
              e.  print(Sales.loc['Shruti',2016])
              f.  Sales.loc["Sumeet"]=[196.2,37800,52000,78438,38852]
              g.  Sales.drop(columns=2014,inplace=True)
              h.  Sales.drop("Kinshuk",axis=0, inplace=True)
              i.  Sales=sales.rename({"Ankit":"Vivaan","Madhu":"Shailesh"}, axis="index")
              j.  Sales.loc["Shailesh",2018] = 100000
              k.  Sales.to_csv("salesFigures.csv",index=False,header=False)
              l.  SalesRetrieved=pd.read_csv("salesFigures.csv", header=None)
                print(SalesRetrieved)
                SalesRetrieved.columns = ['2014','2015','2016', '2017','2018']
                SalesRetrieved.index=['Madhu', 'Kusum', 'Kinshuk', 'Ankit', 'Shruti','Sumeet']
                print(SalesRetrieved)
           7.  Write the statement to install the python connector to connect MySQL i.e. pymysql.
         Ans.  pip install mysql-connector-python
              OR
              pip install pymysql
           8.  Explain the difference between pivot() and pivot_ table() function?
         Ans.   pivot() is a reshaping function in Pandas that reshapes a DataFrame based on unique values in a single column, creating
              a new column for each unique value.
              pivot_table()  is  a  versatile  function  that  not  only  reshapes  data  but  also  allows  aggregation  of  values,  handling
              duplicate entries, and specifying multiple index/column levels for more complex reshaping and summarization tasks.
           9.  What is sqlalchemy?
         Ans.  SQLAlchemy is a library that facilitates the communication between Python programs and databases.

          10.  Can you sort a DataFrame with respect to multiple columns?
         Ans.  Yes. We can use the following statement to sort the DataFrame by multiple columns (say, A, B):

              sortedDF = df.sort_values(by=['A', 'B'])
          11.  What are missing values? What are the strategies to handle them?
         Ans.  If a value corresponding to a column is not present, it is considered to be a missing value.
              A missing value is denoted by NaN.
              There are two most common strategies for handling missing values as mentioned below:
                 i.  Drop the rows/columns having missing values,
                 ii.  Fill or estimate the missing value
          12.  Define the following terms: Median, Standard Deviation and variance.
         Ans.  Median
              The median is the middle value of a dataset, separating it into two equal halves. Function median() returns the median
              from a set of numbers along the requested axis. It returns the median value that separates the higher half from the lower
              half of a set of values.






          84   Touchpad Informatics Practices-XII
   93   94   95   96   97   98   99   100   101   102   103