Python Pandas Tutorial 4: Read Write Excel CSV File




[ad_1]

This tutorial covers how to read/write excel and csv files in pandas. We will cover,
1) Different options on cleaning up messy data while reading csv/excel files
2) Use convertors to transform data read from excel file
3) Export only portion of dataframe to excel file

Topics that are covered in this Python Pandas Video:
0:00 Introduction
1:26 Read CSV file using read_csv() method
2:39 Skip rows in dataframe using “skiprows”
4:44 Import data from CSV file with “null header”
6:28 Read limited data from CSV file
7:19 Clean up messy data from file “not available” and “n.a.” replace with “na_values”
9:01 Supply dictionary for replace with “na_values”
11:40 Write dataframe into “csv” file with “to_csv() method”
15:27 Read excel file using read_excel() method
18:03 Converters argument in read_excel() method
20:17 Write dataframe into “excel” file with “to_excel() method”
22:56 Use ExcelWritter() class
25:13 All properties for Read Write Excel CSV File

Very Simple Explanation Of Neural Network: https://www.youtube.com/watch?v=ER2It2mIagI

Code (jupyter notebook link): https://github.com/codebasics/py/tree/master/pandas/4_read_write_to_excel

Next Video:
Python Pandas Tutorial 5: Handle Missing Data: fillna, dropna, interpolate: https://www.youtube.com/watch?v=EaGbS7eWSs0&list=PLeo1K3hjS3uuASpe-1LjfG5f14Bnozjwy&index=5

Popular Playlist:
Complete python course: https://www.youtube.com/playlist?list=PLeo1K3hjS3uv5U-Lmlnucd7gqF-3ehIh0

Data science course: https://www.youtube.com/playlist?list=PLeo1K3hjS3us_ELKYSj_Fth2tIEkdKXvV

Machine learning tutorials: https://www.youtube.com/playlist?list=PLeo1K3hjS3uvCeTYTeyfe0-rN5r8zn9rw

Pandas tutorials: https://www.youtube.com/playlist?list=PLeo1K3hjS3uuASpe-1LjfG5f14Bnozjwy

Git github tutorials: https://www.youtube.com/playlist?list=PLeo1K3hjS3usJuxZZUBdjAcilgfQHkRzW

Matplotlib course: https://www.youtube.com/playlist?list=PLeo1K3hjS3uu4Lr8_kro2AqaO6CFYgKOl

Data structures course: https://www.youtube.com/playlist?list=PLeo1K3hjS3uu_n_a__MI_KktGTLYopZ12

Data Science Project – Real Estate Price Prediction: https://www.youtube.com/watch?v=rdfbcdP75KI&list=PLeo1K3hjS3uu7clOTtwsp94PcHbzqpAdg

To download csv and code for all tutorials: go to https://github.com/codebasics/py, click on a green button to clone or download the entire repository and then go to relevant folder to get access to that specific file.

Website: http://codebasicshub.com/
Facebook: https://www.facebook.com/codebasicshub
Twitter: https://twitter.com/codebasicshub

Source


[ad_2]

Comment List

  • codebasics
    November 23, 2020

    Step by step roadmap to learn data science in 6 months: https://www.youtube.com/watch?v=H4YcqULY1-Q

  • codebasics
    November 23, 2020
  • codebasics
    November 23, 2020

    I'm blessed , that i found your channel at the very beginning of my self taught journey, u r such a wise personality

  • codebasics
    November 23, 2020

    just completed this video and also I am taking notes. Moving to next video 🙂

  • codebasics
    November 23, 2020

    Thank you for your fantastic tutorial! You have helped me tremendously!

  • codebasics
    November 23, 2020

    Sir the series is a great one to learn. But it would be great if you could have hosted the required dataset elsewhere or in a different repe. I had to clone to entire repo which had other things. So now I am doing copy and pasting csv in raw format from github!

  • codebasics
    November 23, 2020

    df.to_csv("C:/Users/kalhara/Desktop/new2.csv",columns=["tickers","price"]) i use this code but i show error message KeyError Traceback (most recent call last)

    <ipython-input-33-067f5a9f8331> in <module>

    —-> 1 df.to_csv("C:/Users/kalhara/Desktop/new2.csv",columns=["tickers","price"])

  • codebasics
    November 23, 2020

    Sir, my pc is not reading the csv file that I stored in desktop
    It says that file doesn't exist
    So, how to resolve this problem

  • codebasics
    November 23, 2020

    Another first class video. Great detail without the complexity. Thanks!

  • codebasics
    November 23, 2020

    Sir, I don't know what is the problem
    My CSV file is not reading

  • codebasics
    November 23, 2020

    I want to remove NAN values from empty sheet how to do that?

  • codebasics
    November 23, 2020

    please suggest how to change the attached code with my own image dataset in my pc

    # load MNIST dataset
    import urllib, gzip, pickle

    mnistfile = 'mnist.pkl.gz'
    if not os.path.isfile(mnistfile):
        url = urllib.request.URLopener()
        url.retrieve("http://deeplearning.net/data/mnist/mnist.pkl.gz&quot;, mnistfile)
    f = gzip.open(mnistfile, 'rb')

    training_set, validation_set, testing_set = pickle.load(f, encoding='latin1')

    f.close()

    X_train,    y_train    = training_set
    X_validate, y_validate = validation_set
    X_test,     y_test     = testing_set

  • codebasics
    November 23, 2020

    Hi, I am getting below error while importing file.
    Can you help me to overcome this issue.

  • codebasics
    November 23, 2020

    hi..sir..how to read xls file python

  • codebasics
    November 23, 2020

    Extremely helpful.Thanks.

  • codebasics
    November 23, 2020

    Great tutorial and most of it works for me, but I do have one question. When I read my CSV file just like you, the output is not a table like structure but simply a list of rows with all values included but just separated by comma. How do I get it to show up like a table like you?

  • codebasics
    November 23, 2020

    2:47 sir you are reading Excel file with read_csv function???
    Is it possible??

  • codebasics
    November 23, 2020

    Sir content is very good but your voice sometimes goes down 😅
    Please eat 🌶. 😅

  • codebasics
    November 23, 2020

    Seriously i never know that read function could be a bit challenging too

  • codebasics
    November 23, 2020

    Hey guys got a question… How do you give the file name?… Because whenever I put as df = pd.read_csv('train.csv')
    Whenever I put this code it shows file not found…. So what should I do… But it is there in my system… I have even tried other ways like df = pd.read_csv(r'#and here the file location') and still it shows file not found error … What to do?

  • codebasics
    November 23, 2020

    Only we can take value from excel not ms excel 2007 in pandas?

  • codebasics
    November 23, 2020

    Why didn't you do this on pycharm

  • codebasics
    November 23, 2020

    I have my file in desktop (Excel ) how to provide path

  • codebasics
    November 23, 2020

    Great video! Thank you.

  • codebasics
    November 23, 2020

    First of all, this the best tutorial I have seen on python and secondly you mention something else where people might have question in that topic. You answered all my questions when you are teaching. YOU ARE THE BEST!

  • codebasics
    November 23, 2020

    Dear Sir, I truly appreciate your teaching style: always clear, straight to the point, and thorough enough to cover the logics behind each task! I also like how you break things down to simple terms using plain English so that IT challenged people like me can easily understand! I will stay tuned to your YouTube channel while continuing to learn python! Best Regards👍

  • codebasics
    November 23, 2020

    How can we use write function to already opened excel file??

  • codebasics
    November 23, 2020

    Very simple method but in my case it is not working and my spyder is displaying an error as 'no file exists in mnc_1'

  • codebasics
    November 23, 2020

    you helped me in my assignment. thank you

  • codebasics
    November 23, 2020

    i am unable to download the code.
    i can see on github. Please help!
    Thanks in advance.😊

Write a comment