Git Product home page Git Product logo

codebasics / py Goto Github PK

View Code? Open in Web Editor NEW
6.6K 6.6K 16.6K 196.66 MB

Repository to store sample python programs for python learning

Python 0.82% Jupyter Notebook 98.95% HTML 0.12% JavaScript 0.06% CSS 0.04%
jupyter jupyter-notebook jupyter-notebooks jupyter-tutorial numpy numpy-arrays numpy-tutorial pandas pandas-dataframe pandas-tutorial python python-pandas python-tutorial python-tutorials

py's Introduction

py

Repository to store sample Python programs.

This repository is meant for beginners to assist them in their learning of Python. The repository covers a wide range of algorithms and other programs, and would prove immensely helpful for everybody interested in Python programming.

If this is your first time coding in Python, I would love to suggest you begin from the Basics. They are simple to understand and hopefully will prove fun to you.

You can also pay a visit to my very own Youtube channel.

Contributions to the repository are welcome.

CodeBasics.

Happy coding!

py's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

py's Issues

Missing libraries in py/ML/15_gridsearch/15_grid_search.ipynb

Hi, first of all, thanks for this page it helped me a lot, but I noticed you forgot to import numpy and cossval_score after the title Aproach 2.

I used it like this:

import numpy as np
from sklearn.model_selection import cross_val_score

That's all

Issue converting 3-dimensional dataframe to 3-dimensional array

I first created an array: (3 dimensional array)

nlist= [[[1,2,3],[4,5,6],[7,8,9]],[[10,11,12], [13,14,15], [16,17,18]],[[19,20,21],[22,23,24],[25,26,27]]]
import numpy as np
narray = np.array(nlist)

Then I converted it into a dataframe using: (3 dimensional DataFrame)

import pandas as pd
df = pd.DataFrame.from_records(narray)

So I basically converted a 3-dimensional array to a 3-dimensional dataframe.
Now when I try to get it back as an array using:

new_list = np.array(df)

Now this returns a 2-dimensional array. But I want the original 3-dimensional array. What do I do?

Double Linked List Exercise Error

I tried to add an element using insert_at_begining in empty double linked list and got an error

AttributeError: 'NoneType' object has no attribute 'prev'

class Node:
    def __init__(self, data=None, next=None, prev=None):
        self.data = data
        self.next = next
        self.prev = prev
class DoublyLinkedList:
    def __init__(self):
        self.head = None

    def print_forward(self):
        if self.head is None:
            print("Linked list is empty")
            return

        itr = self.head
        llstr = ''
        while itr:
            llstr += str(itr.data) + ' --> '
            itr = itr.next
        print(llstr)

    def print_backward(self):
        if self.head is None:
            print("Linked list is empty")
            return

        last_node = self.get_last_node()
        itr = last_node
        llstr = ''
        while itr:
            llstr += itr.data + '-->'
            itr = itr.prev
        print("Link list in reverse: ", llstr)

    def get_last_node(self):
        itr = self.head
        while itr.next:
            itr = itr.next

        return itr

    def get_length(self):
        count = 0
        itr = self.head
        while itr:
            count+=1
            itr = itr.next

        return count

    def insert_at_begining(self, data):
        node = Node(data, self.head, None)
        self.head.prev = node
        print(self.head.prev)
        self.head = node

    def insert_at_end(self, data):
        if self.head is None:
            self.head = Node(data, None, None)
            return

        itr = self.head

        while itr.next:
            itr = itr.next

        itr.next = Node(data, None, itr)

    def insert_at(self, index, data):
        if index<0 or index>self.get_length():
            raise Exception("Invalid Index")

        if index==0:
            self.insert_at_begining(data)
            return

        count = 0
        itr = self.head
        while itr:
            if count == index - 1:
                node = Node(data, itr.next, itr)
                if node.next:
                    node.next.prev = node
                itr.next = node
                break

            itr = itr.next
            count += 1

    def remove_at(self, index):
        if index<0 or index>=self.get_length():
            raise Exception("Invalid Index")

        if index==0:
            self.head = self.head.next
            self.head.prev = None
            return

        count = 0
        itr = self.head
        while itr:
            if count == index:
                itr.prev.next = itr.next
                if itr.next:
                    itr.next.prev = itr.prev
                break

            itr = itr.next
            count+=1

    def insert_values(self, data_list):
        self.head = None
        for data in data_list:
            self.insert_at_end(data)


if __name__ == '__main__':
    ll = DoublyLinkedList()
    # ll.insert_at_begining(10)
    # ll.insert_values(["banana","mango","grapes","orange"])
    # ll.print_forward()
    # ll.print_backward()
    # ll.insert_at_end("figs")
    # ll.print_forward()
    # ll.insert_at(0,"jackfruit")
    # ll.print_forward()
    # ll.insert_at(6,"dates")
    # ll.print_forward()
    # ll.insert_at(2,"kiwi")
    ll.insert_at_begining('naveen')
    ll.print_forward()

Wrong prediction for values of bath less than bhk

suppose we need to find price of a house with 2 baths and 3 bhk .its price is lower than with 2 baths and 2 bhk.
One more suggestion:
if put absurd values like:
1000sqft and 50 bhk then it should return not available but this model is predicting the price of this also. And suppose if we searched for 1000 sqft with 1000 bhk I know that is invalid but this model shows price in negative also. I think this should be corrected.

Multiprocessing

Hi

I got your code from multiprocessing_pool to run as an example.

I copied exactly but in Jupyter i get nothing, no finished print is shown. (kernel keeps busy).

Thanks for your help.

insertAtBegin method is not working in double linked list in your solution.

Hello,

Thanks for the lesson on linked list. I understood it completely.

This should work. Please update.

def insertAtBegin(self, data):
if self.head is None:
node = Node(data, self.head, None)
self.head = node
return
node = Node(data, self.head, None)
node.next = self.head
self.head.prev = node
self.head = node

Updated sqldump for sales insights project

Need help here to generate updated db_dump.sql file. I did this sales insights series: https://www.youtube.com/playlist?list=PLeo1K3hjS3uva8pk1FI3iK9kCOKQdz1I9 Here in tutorial 9 I built a new dashboard that has new data. I think in one of the tables I added 2 or 3 columns. The issue is the columns were added directly to power BI. What we need to do now is,

  1. Take those extra columns and transfer them to mysql. new columns are available in updated .pbix file
  2. Once you have those columns in mysql -> export it to db_dump_version_2.sql file
    Give me a PR to add this new .sql file in this repo. Many people have asked for this and I do not have time so if someone can do this, I'd be very thankful.

Good

##This is good*

Typo error

File path: py/TechTopics/CodingBestPractices/coding_best_practices.md
Line of code: 130

Current: "return live above is so tricky and cryptic that it could give a headache to a person reading that code"
Correct: "return line above is so tricky and cryptic that it could give a headache to a person reading that code"

Amendment: live ---> line

New Programs

I would like to add some new programs as it would be helpful for anyone who sees this and also it will improve my python skills.

13_read_write

13_read_write 中的代码在执行with open("poem.txt","r") as f:这句代码时,会报UnicodeDecodeError: 'gbk' codec can't decode byte 0x94 in position 659: illegal multibyte sequence 这样的错误
即使把代码更改成 with open("poem.txt",encoding='utf-8').read() as f: 也会报AttributeError: __enter__这样的错
明明 file 已经内置了对上下文管理协议的支持,可仍然要报错

Error running face_cascade.detectMultiScale

Following code from this file in celebrity recognition project does not work:

face_cascade = cv2.CascadeClassifier('./opencv/haarcascades/haarcascade_frontalface_default.xml')
eye_cascade = cv2.CascadeClassifier('./opencv/haarcascades/haarcascade_eye.xml')

faces = face_cascade.detectMultiScale(gray, 1.3, 5)
faces

Error:

---------------------------------------------------------------------------

error                                     Traceback (most recent call last)

<ipython-input-9-17af89ccf870> in <module>()
      4 # eye_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_eye.xml')
      5 
----> 6 faces = face_cascade.detectMultiScale(gray, 1.3, 5)
      7 faces

error: OpenCV(4.1.2) /io/opencv/modules/objdetect/src/cascadedetect.cpp:1689: error: (-215:Assertion failed) !empty() in function 'detectMultiScale'

Missing value

In the age column, there are 177 Nan. How to deal with whether should I delete them or put the mean of age column??

Contribution for basic simple python exercises

Everyone, I am desperately looking for some volunteers who can help me come up with basic python exercises. This should be an easy as well as fun task for you. Whoever contributes the most will get 30 min zoom/watsapp conversation with me. I can give you career guidance or answer any questions you have.

Here is what I am looking for,

  1. Check this: https://github.com/codebasics/py/tree/master/Basics/Hindi It has exercises only till read write file module.
  2. Now my python tutorial playlist has 41 videos: https://www.youtube.com/playlist?list=PLeo1K3hjS3uv5U-Lmlnucd7gqF-3ehIh0
  3. Can you create simple exercise description and a solution file similar to,
    Description: https://github.com/codebasics/py/blob/master/Basics/Hindi/12_read_write_file/read_write_file_exercise.md
    Solution: Click on solution links in above md file
  4. You need to do this for any video after read write file
  5. I'd be really thankful if people can help me put together exercises for all remaining videos. I am super busy with deep learning and data structures series and do not have time to work on this
  6. You just need to fork the repo and give me a PR

Project turism!

I watch a great marketplace on my country.
I live in Ecuador and the country have good opportunities on the turism market.
I have a idea to connect the people, but I need some help.
I have basic skills on development. Thanks.
Psdt: great business

Csv File

I cant download the csv file I was following the you tube lecture of data science but I was unable to download the csv file from it please help I need the file for practicing

Request to update pandas code sample to match latest version

Hi,
When I use your code samples of panda, namely "import pandas.io.data as web", jupyter throws a module not found error. I tried replacing it with "import pandas_datareader.data but still getting some error. Request you to give me pointers how to fix this or please help with updated code samples. I have been following your python series and I had found it very useful.

Error type

Here is an word "Pepal" was written by mistake, instead of "Petal"
I'll show it to you in the screenshot.

error

Column Names have spaces in them

column names in CSV file have spaces in them which certainly makes it impossible to call using '.' also when you edit a csv file it changes it seems to change its formatting and everything just messes up.

Folders numbered incorrectly

In the Data Structures folder, the folder numbering starts from 2 and goes up to 10 with number 4 and number 9 occurring for more than one folders. The problem is that there is no folder numbered '1' in the entire list. This sets a beginner back, and misguides them about the level of difficulty that I assumed each number carries.

Consider renumbering the folders with the Arrays folder numbered as 1.

insertion at begining

Hi ,
In doublylinkedlist.py

when I try to print this statement i'm getting error:
if name == 'main':
ll = DoublyLinkedList()
ll.insert_at_begining("mango")

plse try to use this insert_at_begining() first and see the case.

Jupyter files are not opening

Hi Sir,
As I am learning ML , earlier i used to get jupyter file from your github and now it's showing blank. Please do the needful.
Capture

Update the plots

The linear regression notebooks do not contain the ##matplots. This makes me question how or why the linear regression was chosen in the first place?
#24
OneHotEncoding

how to do hyperparameter tuning using K Fold cross-validation

import pandas as pd
from matplotlib import pyplot as plt
import numpy as np
df = pd.read_csv(r"C:\Users\mdmar\Downloads\Thesis\Data/1024.csv")
#print(df.head())
#sizes = df['target'].value_counts(sort=1)
#print(sizes)
#Define dependent variable
Y = df['target'].values
Y=Y.astype('int')
#define independent variable
X = df.drop(labels=['target'], axis=1)
#Split dataset for train and test
from sklearn.model_selection import train_test_split
X_train, X_test, Y_train, Y_test=train_test_split(X,Y,test_size=0.30, random_state=30)
#print(X_train)
#Import Random Forest
from sklearn.ensemble import RandomForestClassifier
model = RandomForestClassifier(n_estimators=70, random_state=40)
model.fit(X_train,Y_train)
prediction_test = model.predict(X_test)
print(prediction_test)
from sklearn import metrics
print("Accuracy:",metrics.accuracy_score(Y_test, prediction_test)*100,'%')
print(model.feature_importances_)
print(model.feature_importances_*100,'%')
Out : [1 1 1 0 0 1 1 1 1 1 1 1 0 1 1 0 0 1 1 0 1 0 0 0 1 1 1 1 1 1 0 1 0 1 0 1 1
1 0 0 1 1 1 0 0 0 1 1 0 0 1 1 1 1 1 1 0 0 0 0 1 1 1 0 0 0 1 0 0 1 0 1 0 0
0 0 1 1 0 0 0 1 0 0 1 1 0 0 0 1 0 0 1 0 0 0 0 0 0 1 1 0 0 1 1 0 1 0 0 0 0
0 0 1 0 0 0 0 1 0 1 0 0 1 1 1 0 1 0 1 0 0 1 1 1 1 1 0 0 0 0 1 0 1 0 0 1 1
0 0 0 0 1 0 1 0 0 1 1 1 0 0 0 1 0 1 1 1 1 1 1 1 1 0 0 1 0 0 0 1 0 0 1 0 0
0 0 0 1 1 1 0 1 1 1 0 1 1 1 1 1 0 0 1 1 0 0 0 1 0 0 1 0 1 0 0 0 0 1 1 1 0
0 0 0 1 0 0 1 1 1 1 1 1 0 1 0 1 0 0 1 0 0 0 0 1 1 0 1 1 1 0 0 1 0 1 1 0 0
1 1 1 1 1 0 1 0 0 0 1 0 0 1 0 1 0 0 0 1 0 0 1 1 1 0 1 0 0 1 0 0 0 1 0 1 1
1 0 0 1 0 1 0 0 1 1 1 1]
Accuracy: 97.72727272727273 %
[0.1031516 0.0358877 0.11881306 0.09649581 0.09640051 0.01116345
0.02173903 0.13786201 0.06464796 0.13677327 0.05528801 0.12177758]
[10.31516006 3.58876957 11.88130644 9.64958137 9.64005136 1.11634483
2.17390296 13.78620058 6.46479635 13.67732725 5.52880149 12.17775775] %

how to do hyperparameter tuning using K Fold cross-validation using this model

Expanding the career track list

Excellent work and excellent suggestions, thank you for sharing.

It struck me that your choice of career tracks might be somewhat restrictive.

Cloud, Automation, Cybersecurity, and DevOps could be similarly desirable career tracks options. Also, there might be others that I missed here.

In fact, it would be great if you could outline a DevOps 2020 step-by-step roadmap or give any pointer to one that you consider valuable.

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.