100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
Summary Python Data Operations Notes $5.88   Add to cart

Summary

Summary Python Data Operations Notes

 2 views  0 purchase
  • Course
  • Institution

Notes of python data operations using pandas, covered in the Principles of Programming course, part of the Computer Science and AI bachelor degree. The notes are initially written in Jupyter Notebook, here in pdf format. They contain practical examples of data operations in python and images to exp...

[Show more]

Preview 2 out of 15  pages

  • December 8, 2022
  • 15
  • 2022/2023
  • Summary
avatar-seller
Pandas Data Operations

import pandas as pd
import numpy as np



What is a Dataframe?
A dataframe is a data type provided by the library pandas
It is the most relevant data type to work with tables and data in python
Imagine dataframe as a table created by rows and colummns where each row and column
is an object type pandas.Series (vector/list). Each element contains a label.



Create a DataFrame
Adding data manually

Lists of lists
Nested dictionaries
Reading the information from .csv file

Using the function pd.read_csv() with the path of the file.


#create 2D array with data
data_lst = [
['A3', 0, -1, 0, 'si'],
['B1', 1, None, 0, 'no'],
['B3', 4, None, 0, 'no'],
['B3', 5, 1, 0, 'si'],
['A1', 4, 0, None, None],
['A3', 1, 2, 1, 'si'],
['C2', 4, 1, 1, 'no']
]

data_lst

[['A3', 0, -1, 0, 'si'],
['B1', 1, None, 0, 'no'],
['B3', 4, None, 0, 'no'],
['B3', 5, 1, 0, 'si'],
['A1', 4, 0, None, None],
['A3', 1, 2, 1, 'si'],
['C2', 4, 1, 1, 'no']]


#print first column
col0 = []

, for row in data_lst:
col0.append(row[0])

col0

['A3', 'B1', 'B3', 'B3', 'A1', 'A3', 'C2']

#create test dataframe
test_df = pd.DataFrame(
data_lst
)
test_df


0 1 2 3 4

0 A3 0 -1.0 0.0 si

1 B1 1 NaN 0.0 no

2 B3 4 NaN 0.0 no

3 B3 5 1.0 0.0 si

4 A1 4 0.0 NaN None

5 A3 1 2.0 1.0 si

6 C2 4 1.0 1.0 no



#update index of rows and columns
test_df = pd.DataFrame(
data_lst,
columns=['A', 'B', 'C', 'D', 'E'],
index=[f'row{i}' for i in range(1, 8)]
)
test_df


A B C D E

row1 A3 0 -1.0 0.0 si

row2 B1 1 NaN 0.0 no

row3 B3 4 NaN 0.0 no

row4 B3 5 1.0 0.0 si

row5 A1 4 0.0 NaN None

row6 A3 1 2.0 1.0 si

row7 C2 4 1.0 1.0 no




DataFrame structure

The benefits of buying summaries with Stuvia:

Guaranteed quality through customer reviews

Guaranteed quality through customer reviews

Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.

Quick and easy check-out

Quick and easy check-out

You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.

Focus on what matters

Focus on what matters

Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!

Frequently asked questions

What do I get when I buy this document?

You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.

Satisfaction guarantee: how does it work?

Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.

Who am I buying these notes from?

Stuvia is a marketplace, so you are not buying this document from us, but from seller beatricemossberg. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

No, you only buy these notes for $5.88. You're not tied to anything after your purchase.

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

75323 documents were sold in the last 30 days

Founded in 2010, the go-to place to buy study notes for 14 years now

Start selling
$5.88
  • (0)
  Add to cart