Python CSV files - with PANDAS

Поделиться
HTML-код
  • Опубликовано: 11 дек 2024

Комментарии • 49

  • @bengray1054
    @bengray1054 9 месяцев назад +6

    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 Год назад +5

    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 5 месяцев назад +1

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

  • @dicasdetop
    @dicasdetop 7 месяцев назад +1

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

  • @EndBL
    @EndBL Год назад +1

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

  • @kanwisher
    @kanwisher Год назад +1

    Clear and easy, just what I was looking for

  • @hannahreynolds2800
    @hannahreynolds2800 3 года назад +2

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

  • @markhamilton1292
    @markhamilton1292 3 года назад +4

    Direct and to the point, well done!

  • @isabellaj4608
    @isabellaj4608 7 месяцев назад +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 11 дней назад

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

  • @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?

  • @yanwenwei5462
    @yanwenwei5462 3 года назад +3

    Thank you, John. It helped my assignment.

  • @sabinomuniz5542
    @sabinomuniz5542 Год назад

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

  • @saifazeem8158
    @saifazeem8158 3 года назад +2

    Quite useful, Keep up the good work! ❤️

  • @ThiagoSimoes79
    @ThiagoSimoes79 Год назад +1

    Thanks mate. Help me a lot.

  • @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 Год назад

      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 Год назад

      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 Год назад

      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.

  • @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?

  • @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.

  • @technikalproblem6780
    @technikalproblem6780 2 года назад +1

    Thank you so much! This worked.

  • @bleuthner
    @bleuthner Год назад +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  Год назад

      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!

  • @onkarnardekar6491
    @onkarnardekar6491 3 года назад +1

    Thankyou Soooo Muchhh for this video

  • @aces9905
    @aces9905 2 года назад

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

    • @jayyvibing9539
      @jayyvibing9539 Год назад

      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.

  • @saisanthosh8370
    @saisanthosh8370 3 года назад +1

    deserved more subs

  • @bleuthner
    @bleuthner Год назад

    Src-File ?

  • @dzeykop
    @dzeykop 3 года назад

    Thank you John, 👏👍

  • @python360
    @python360 4 года назад +2

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

  • @MachineLearningPro
    @MachineLearningPro Год назад

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

  • @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 года назад +2

      Sure, its' VS Code. It's free. I did a video on a basic Windows Python setup here: ruclips.net/video/EJUdFB5iu7Y/видео.html if you are interested.

    • @lutfullayuldashev6278
      @lutfullayuldashev6278 4 года назад

      @@JohnWatsonRooney thanks for response!

  • @breandensamas8623
    @breandensamas8623 4 месяца назад

    Good one

  • @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 ?

  • @simbarashechibgwe4497
    @simbarashechibgwe4497 3 года назад

    Thanks John

  • @sheikhm9407
    @sheikhm9407 Год назад +1

    Great!!

  • @anurajms
    @anurajms 2 года назад +1

    thank you

  • @ZyngastiC
    @ZyngastiC 3 месяца назад

    Thanks!!!!

  • @jholmes724
    @jholmes724 2 года назад +1

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

  • @atetetega2468
    @atetetega2468 5 месяцев назад

    Your raw data

  • @abd5184
    @abd5184 Год назад +4

    Tough British accent