0% found this document useful (0 votes)
17 views

02 Practical 002

Uploaded by

Pawan Raut
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
17 views

02 Practical 002

Uploaded by

Pawan Raut
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 3
GQ In Practical 2: Exploring Pandas Data Structures Aim: Understand the Pandas library and its primary data structures. Theory: Pandas is @ popular Python library for data manipulation and analysis. Itprovides two primary data structures: Series and DataFrame. Series: A one-dimensional labeled array capable of hélding any data type. It is similar to a NumPy array but with labeled indices, making data alignmentland indexing more: convenient. DataFrame: A two-dimensional labeled data structure withicolumns of potentially different data types. Its like a spreadsheet or SQL table, where data can be easily manipulated and analyzed. Some important concepts to undlerstand in Pandas are: Creating Series and DataFrame: Creating Series using pd.Series() and DataFrame using pd.DataFrame(). Data Exploration: Aétessing rows, columns, and specific data from a DataFrame. Data Cleaning: Handling missing data, duplicate data, and performing data transformations. DatalVisualization,Basic visualization Using Pandas built-in plotting capabilites. Example Programsialong with concepts: 1. Creating Series and DataFrame: import pandas as pd # Creatmipa Series series_data = pd.Series([1e, 20, 30, 49, 5@]) print (Series data) @ 10 1 20 2 30 3 40 4 50 dtype: intes # Creating a DataFrane data = {‘Name’: ['Alice*, "Bob", ‘Charlie’, ‘David"], *Age': [25, 30, 35, 40], City's ['New York", ‘London*, ‘Paris’, ‘Tokyo"]} df = pd.DataFrane(data) print (oF) In [4] In [5] In [6] In, In [8] Name Age city @ Alice 25 New York 1 Bob 3@ London 2 Charlie 35 Paris 3 David 4 © — Tokyo 2. Data Exploration: import pandas as pd # Accessing columns print (d#[ ‘Name’ }) @ Alice 1 Bob 2 Charlie 3 David Name: Name, dtype: object # Accessing rows using iloc (integer-based indexing) print (éf.i1oc[1}) Name Bob Age 30 London 1, dtype: object # Accessing rows using loc (Label-based indexing) pein) some ah a Cy nae rs fon 2) # Accessing specific print(df.at(1, 'Name'] Bob ata Cleaning: # Removing duplicates df with duplicates = pd.Dataframe({'A": [1, 2, 2, 3, 3]})) df_deduplicated = df_with_duplicates.drop_duplicates() # Drop duplicate rows print(df_deduplicated) ree # Data transformation dF[‘Age'] = df[*Age’] +2 # Add 2 to each Age value printf) Name Age City mice “27 New York ( e 1 Bob 32 _London 2 Charlie 37 Paris 3 David 42 Tokyo Assignments: 1. Create a Series with the following data: 25, 30, 35, 40, 45, 50, 55, 60. Set ct arecerarert art: 2. Create a DataFrame with the following data: Name Age City emily a7 Jecob 31 La Emma 29 Pais Benjamin 33 Sydney 1. Access the ‘Age’ column of the DataFrame. 2. Access the ‘City’ value o ith index label 'c'. 3. Replace the ‘Age’ va ew\with index label 'e' to 48. 4, Drop the ‘City’ Conclusion: In this practical, we explored the Pahidas library and learned about its primary data res, Series, and DataFrame, We performed various operations like data exploration, cleaning, and data transformation using Pandas functions. Pandas is an essential tool manipulation and analysis in data science projects.

You might also like