Python CSV files - with PANDAS

แชร์
ฝัง
  • เผยแพร่เมื่อ 7 ก.พ. 2025
  • Learn the basics of manipulating CSV files with Pandas in Python. Take order information and split it out based on criteria
    -------------------------------------
    twitter / jhnwr
    code editor code.visualstu...
    WSL2 (linux on windows) docs.microsoft...
    -------------------------------------
    Disclaimer: These are affiliate links and as an Amazon Associate I earn from qualifying purchases
    mouse amzn.to/2SH1ssK
    27" monitor amzn.to/2GAH4r9
    24" monitor (vertical) amzn.to/3jIFamt
    dual monitor arm amzn.to/3lyFS6s
    microphone amzn.to/36TbaAW
    mic arm amzn.to/33NJI5v
    audio interface amzn.to/2FlnfU0
    keyboard amzn.to/2SKrjQA
    lights amzn.to/2GN7INg
    webcam amzn.to/2SJHopS
    camera amzn.to/3iVIJol
    gfx card amzn.to/2SKYraW
    ssd amzn.to/3lAjMAy

ความคิดเห็น • 49

  • @bengray1054
    @bengray1054 10 หลายเดือนก่อน +7

    This video is awesome. I am a novice at python and so far NOTHING has come as close to this video in terms of showcasing just how simple pandas makes reading data!

  • @auggiea9195
    @auggiea9195 ปีที่แล้ว +6

    Just started learning Python for my degree 2 weeks ago and this was so helpful! Thank you!!

  • @nseworld5521
    @nseworld5521 2 ปีที่แล้ว +4

    thank you man! you know, it`s first time i`m using python in my entry to data analytics) i thought it would be much harder to understand code, but the way you give information makes me feel so ez

  • @uteshiyadharmesh
    @uteshiyadharmesh 7 หลายเดือนก่อน +1

    Exact whatever I was looking for to quick start my pandas journey! Thanks for such an awesome video! Love it!

  • @EndBL
    @EndBL ปีที่แล้ว +1

    thank you John!
    can't wait to watch harder videos about panda csv

  • @markhamilton1292
    @markhamilton1292 3 ปีที่แล้ว +4

    Direct and to the point, well done!

  • @kanwisher
    @kanwisher ปีที่แล้ว +1

    Clear and easy, just what I was looking for

  • @NormasABNTorg
    @NormasABNTorg 9 หลายเดือนก่อน +1

    man, honestly i appreciate your video, I loving coding with you, wish you, a good person, stay safe always

  • @isabellaj4608
    @isabellaj4608 9 หลายเดือนก่อน +1

    man you saved my assignment with 5:12 I couldn't understand how to do it for the life of me lol

    • @warl0rdshorts
      @warl0rdshorts 2 หลายเดือนก่อน

      Help me I can't do it, it says Keyerror: 'Genre' and i know that python is case sensitive idk what's wrong

  • @yanwenwei5462
    @yanwenwei5462 3 ปีที่แล้ว +3

    Thank you, John. It helped my assignment.

  • @hannahreynolds2800
    @hannahreynolds2800 3 ปีที่แล้ว +2

    Would there be a reason why my program keeps saying I have an empty dataframe when I do not

  • @saifazeem8158
    @saifazeem8158 4 ปีที่แล้ว +2

    Quite useful, Keep up the good work! ❤️

  • @andreha_
    @andreha_ 3 ปีที่แล้ว +1

    Video so cool but I have a question. I need to check 2 parameters in two deferent columns how I can do that?

  • @yasseralkindi7350
    @yasseralkindi7350 3 ปีที่แล้ว +3

    Great video as always John - thank you.
    Off the cuff question here - can you do a video on troubleshooting csv imports with pandas? When I've imported a csv file, and df.head(), it sometimes brings in a single column and an index. Other times, it works exactly as expected. Since I don't know what to do with that column, I thought such a video might help?

  • @technikalproblem6780
    @technikalproblem6780 2 ปีที่แล้ว +1

    Thank you so much! This worked.

  • @ThiagoSimoes79
    @ThiagoSimoes79 2 ปีที่แล้ว +1

    Thanks mate. Help me a lot.

  • @bleuthner
    @bleuthner 2 ปีที่แล้ว +1

    Hi, John. Thanks for shareing this video. In the beginning you spoke about the src-file "address-data.csv". Could you please share the link from the source?? I didn't get that!

    • @JohnWatsonRooney
      @JohnWatsonRooney  2 ปีที่แล้ว

      hey, thanks for watching. I'd love to but i made this 3 years ago I don't have any of it any more sorry!

  • @sabinomuniz5542
    @sabinomuniz5542 ปีที่แล้ว

    How can I get the data from a csv file without rewriting all of it to my python program?

  • @adamstephan168
    @adamstephan168 2 ปีที่แล้ว +1

    Awesome video, in this example, if I wanted to move all the '1 Day' and '2 Day' labeled shipping types into the a dataframe titled 'Early_Shipping', how would I write that code?

    • @jayyvibing9539
      @jayyvibing9539 2 ปีที่แล้ว

      1. Import the necessary modules:
      import csv
      2 . Open the .csv file in write mode and create a csv.writer object:
      with open('shipping_times.csv', 'w', newline='') as csvfile:
      writer = csv.writer(csvfile)
      3. Iterate over the rows in the dataset and write the desired rows to the 'Early shipping' column in the .csv file:
      for row in dataset:
      if row[0] == 'Day 1' or row[0] == 'Day 2':
      writer.writerow(['Early shipping'] + row[1:])
      else:
      writer.writerow(row)
      This will write the 'Day 1' and 'Day 2' shipping times to the 'Early shipping' column in the .csv file, and leave the other rows unchanged. Note that this assumes that the shipping times are in the first column of the dataset, and that the .csv file has a header row with the column names. If this is not the case, you may need to modify the code accordingly.

    • @jayyvibing9539
      @jayyvibing9539 2 ปีที่แล้ว

      My other comment provides more information:
      To create a pandas DataFrame with the 'Day 1' and 'Day 2' shipping times under a column called 'Early shipping', you can use the following steps:
      1. Import the necessary modules:
      import pandas as pd
      2. Create a list of the desired rows from the dataset:
      early_shipping = [row for row in dataset if row[0] == 'Day 1' or row[0] == 'Day 2']
      3. Create a DataFrame from the list of rows:
      df = pd.DataFrame(early_shipping, columns=['Early shipping'])
      4. This will create a DataFrame with a single column called 'Early shipping' and one row for each 'Day 1' or 'Day 2' shipping time in the dataset. If you want to include other columns from the dataset in the DataFrame, you can specify them in the columns parameter of the pd.DataFrame constructor. For example:
      df = pd.DataFrame(early_shipping, columns=['Early shipping', 'Other Column', 'Another Column'])
      This will create a DataFrame with three columns: 'Early shipping', 'Other Column', and 'Another Column'. The values in the 'Early shipping' column will be the 'Day 1' and 'Day 2' shipping times, and the values in the other columns will be taken from the corresponding columns in the dataset.

    • @jayyvibing9539
      @jayyvibing9539 2 ปีที่แล้ว

      To combine the two scripts, you can do the following:
      1. Import the necessary modules:
      import csv
      import pandas as pd
      2. Open the .csv file in write mode and create a csv.writer object:
      with open('shipping_times.csv', 'w', newline='') as csvfile:
      writer = csv.writer(csvfile)
      Iterate over the rows in the dataset and write the desired rows to the 'Early shipping' column in the .csv file:
      Copy code
      for row in dataset:
      if row[0] == 'Day 1' or row[0] == 'Day 2':
      writer.writerow(['Early shipping'] + row[1:])
      else:
      writer.writerow(row)
      3. Create a list of the desired rows from the dataset:
      early_shipping = [row for row in dataset if row[0] == 'Day 1' or row[0] == 'Day 2']
      4. Create a DataFrame from the list of rows:
      df = pd.DataFrame(early_shipping, columns=['Early shipping'])
      df = pd.DataFrame(early_shipping, columns=['Early shipping', 'Other Column', 'Another Column'])
      This will first write the 'Day 1' and 'Day 2' shipping times to the 'Early shipping' column in the .csv file, and then create a DataFrame with the 'Day 1' and 'Day 2' shipping times under a column called 'Early shipping'. If you specify additional columns in the columns parameter of the pd.DataFrame constructor, the DataFrame will include those columns as well.

  • @onkarnardekar6491
    @onkarnardekar6491 3 ปีที่แล้ว +1

    Thankyou Soooo Muchhh for this video

  • @Soler4485
    @Soler4485 2 ปีที่แล้ว

    So I am trying to create a pdf file from a csv file but I want to create a code that can take any csv which is inputted into it to create a different pdf depending on the content of the csv. Do you know of any way to do that? I know that to convert to pdfs you need the pdfkit plugin which I have and I have done but I am just not sure how to make the code generalizable.

  • @saisanthosh8370
    @saisanthosh8370 3 ปีที่แล้ว +1

    deserved more subs

  • @dzeykop
    @dzeykop 3 ปีที่แล้ว

    Thank you John, 👏👍

  • @aces9905
    @aces9905 3 ปีที่แล้ว

    Helpful! How do I find the most repeated word in my file?

    • @jayyvibing9539
      @jayyvibing9539 2 ปีที่แล้ว

      Here is one way to find the most repeated word in a .csv file in Python:
      1. First, open the .csv file using the csv module and create a list of the words in the file.
      2. Use the Counter function from the collections module to count the frequency of each word.
      3. Find the word with the highest frequency by using the most_common method of the Counter object.
      Here is some example code that demonstrates this approach:
      import csv
      from collections import Counter
      # Open the .csv file and create a list of the words in the file
      with open('file.csv', 'r') as f:
      reader = csv.reader(f)
      words = []
      for row in reader:
      for word in row:
      words.append(word)
      # Count the frequency of each word
      word_counts = Counter(words)
      # Find the word with the highest frequency
      most_common_word = word_counts.most_common(1)[0][0]
      print(f"The most common word is: {most_common_word}")
      This code will open the .csv file, read the contents into a list of words, count the frequency of each word using the Counter function, and then find the word with the highest frequency using the most_common method. The output will be the most common word in the file.
      Note that this code assumes that each row in the .csv file represents a list of words separated by commas. If your .csv file has a different structure, you may need to modify the code to suit your needs.

  • @MachineLearningPro
    @MachineLearningPro ปีที่แล้ว

    Great video mate! Take a look at my pandas tutorial if you want.

  • @python360
    @python360 4 ปีที่แล้ว +2

    Jupyter notebook is great way of working with Pandas - maybe do a vid on that too?

  • @breandensamas8623
    @breandensamas8623 6 หลายเดือนก่อน

    Good one

  • @sheikhm9407
    @sheikhm9407 ปีที่แล้ว +1

    Great!!

  • @bleuthner
    @bleuthner 2 ปีที่แล้ว

    Src-File ?

  • @anurajms
    @anurajms 2 ปีที่แล้ว +1

    thank you

  • @simbarashechibgwe4497
    @simbarashechibgwe4497 3 ปีที่แล้ว

    Thanks John

  • @lutfullayuldashev6278
    @lutfullayuldashev6278 4 ปีที่แล้ว +1

    Hi John. I m new to python. Still struggling to choose appropriate python application. Tending to use jupyter, however yours look more interesting. Can you please tell the name of this python application (interface)?

    • @JohnWatsonRooney
      @JohnWatsonRooney  4 ปีที่แล้ว +3

      Sure, its' VS Code. It's free. I did a video on a basic Windows Python setup here: th-cam.com/video/EJUdFB5iu7Y/w-d-xo.html if you are interested.

    • @lutfullayuldashev6278
      @lutfullayuldashev6278 4 ปีที่แล้ว

      @@JohnWatsonRooney thanks for response!

  • @ZyngastiC
    @ZyngastiC 5 หลายเดือนก่อน

    Thanks!!!!

  • @jholmes724
    @jholmes724 2 ปีที่แล้ว +1

    Get video, short and to the point. Now do some guitar tutorials, I'll join you. lol

  • @juzarpara5357
    @juzarpara5357 5 ปีที่แล้ว

    With below code I am able to create dataframe
    VAT = comm[comm['Particulars'].str.contains("comm|Britain", case=False)==True]
    VAT
    But I want to create column
    below code does not work
    comm['VAT'] = comm[comm['Particulars'].str.contains("comm|Britain", case=False)==True]
    comm
    Can you provide proper code ?

  • @atetetega2468
    @atetetega2468 7 หลายเดือนก่อน

    Your raw data

  • @abd5184
    @abd5184 ปีที่แล้ว +4

    Tough British accent