Git Product home page Git Product logo

machine-learning-pandas's Introduction

machine-learning-pandas

how can you use pandas in python

Pandas

pandas is a Python package providing fast, flexible, and expressive data structures designed

to make working with “relational” or “labeled” data both easy and intuitive. It aims to be the

fundamental high-level building block for doing practical, real-world data analysis in Python.

Data Structure

Pandas docs: In 0.20.0, Panel is deprecated and will be removed in a future version. The 3-

D structure of a Panel is much less common for many types of data analysis than the 1-D of

the Series or the 2-D of the DataFrame.

1 - Series

import pandas as pd
my_series = pd.Series([1, 2, 3,4,5],index=['row1','row2','row3','row4','row5'])
# result
# row1 1
# row2 2
# row3 3
# row4 4
# row5 5

Show Values

my_series.values
# array([1, 2, 3, 4, 5], dtype=int64)

Show index

my_series.index
# Index(['row1', 'row2', 'row3', 'row4', 'row5'], dtype='object')

Set alphabet label as new index

my_series.index = ['A','B','C','D','E']

DataFrame

Pandas docs : Two-dimensional size-mutable, potentially heterogeneous tabular data

structure with labeled axes (rows and columns). Arithmetic operations align on both row and

column labels. Can be thought of as a dict-like container for Series objects. The primary

pandas data structure

Create DataFrame with Array

import numpy as np
my_array = np.array([[1, 5, 9, 13], [2, 6, 10, 14], [3, 7, 11, 15], [4, 8, 12, 16]])
my_df = pd.DataFrame(my_array, index=['row1' ,'row2' ,'row3' ,'row4'], columns=['col1' ,'col2' ,'col3' ,'col4'])

Create DataFrame with Dictionary

import numpy as np
my_array = np.array([[1, 5, 9, 13], [2, 6, 10, 14], [3, 7, 11, 15], [4, 8, 12, 16]])
my_df = pd.DataFrame(my_array, index=['row1' ,'row2' ,'row3' ,'row4'], columns=['col1' ,'col2' ,'col3' ,'col4'])

Selecting 1

array.loc['row1']['col2']

Selecting 2

array.iloc[2][3]

Edit a DataFrame

array.['col5'] = [20 ,21 ,22 ,23]
# or
array.loc['row1', 'col1'] = 0

Reset index

array.reset_index(drop=True)

Deleting

array.drop('col5',axis=1)
# or
array.drop('row1',axis=0)

Renaming

array.rename(columns={'col4':'col_four'})

sort values

array.sort_values(by='col1',ascending=False)
# or 
array.sort_values(by='col1',ascending=True)

head !!!

it can show you five first rows

array.head()

I hope this data will be useful to you.

machine-learning-pandas's People

Contributors

azibom avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.