Introduction to Pandas DataFrame

In this tutorial, you will learn

 

1.  How to import the Pandas library?

2.  How to create Series Object?

3.  How to create a Pandas DataFrame?

4.  How to display data in Pandas DataFrame?

5.  How to get the Pandas DataFrame summary?

6.  How to display the Pandas DataFrame Index?

7.  How to transpose a DataFrame in Pandas?

8. How to check Null Values in Pandas DataFrame?

9.  How to read files in a DataFrame in Pandas?

10. How to write Pandas DataFrame to a file?

1. Import the Libraries

import pandas as pd

2. Create a Series Object 

series_object=pd.Series([1,2,3,4,5])
series_object
How to create a series object in pandas?

3. Create a Pandas DataFrame                                      

df=pd.DataFrame({'Dates' :['2020-01-01', '2020-01-02', '2020-01-03', '2020-01-04',
               '2020-01-05', '2020-01-06'] ,\
                'ID': [1,2,3,4,5,6],\
                'Names':['A','B','C','D','E','F'],\
                'Designation':['Manager','Employee','CEO','CTO','Manager','Employee']})
df             
how to create a dataframe with column names?

4. Display Data in Pandas DataFrame 

df.head(1)
how to display top row in pandas datafame?
df.tail(1)
how to display the bottom row in pandas dataframe?

5. Pandas DataFrame Summary                                           

df.describe()

6. Pandas DataFrame Index                                               

df.index
how to get pandas dataframe index?

7. Transpose Pandas DataFrame                                               

df.T
how to transpose pandas dataframe?

8. Check Null Values in Pandas DataFrame                                         

df.isna()
how to check null values in pandas dataframe?

9. Read files in Pandas                                          

csv_file=pd.read_csv("file_name.csv")
excel_file=pd.read_excel("file_name.xlsx")

10. Write Files in Pandas                                        

pd.to_csv("file_name.extension")

 Summary

 

1.  Display DataFrame using .head( ) and .tail( ) method.

2.  Transpose a DataFrame using .T( ) method.

3.  Check null values using .isna( ) method.

4.  Read files using pd.read_csv( ) method.

5.  Write files using pd.to_csv( ) method.

 You can find the Github link here.