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!
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
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?
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.
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.
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.
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?
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.
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!
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.
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)?
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 ?
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!
Just started learning Python for my degree 2 weeks ago and this was so helpful! Thank you!!
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
Exact whatever I was looking for to quick start my pandas journey! Thanks for such an awesome video! Love it!
man, honestly i appreciate your video, I loving coding with you, wish you, a good person, stay safe always
thank you John!
can't wait to watch harder videos about panda csv
Clear and easy, just what I was looking for
Would there be a reason why my program keeps saying I have an empty dataframe when I do not
Direct and to the point, well done!
man you saved my assignment with 5:12 I couldn't understand how to do it for the life of me lol
Help me I can't do it, it says Keyerror: 'Genre' and i know that python is case sensitive idk what's wrong
Video so cool but I have a question. I need to check 2 parameters in two deferent columns how I can do that?
Thank you, John. It helped my assignment.
How can I get the data from a csv file without rewriting all of it to my python program?
Quite useful, Keep up the good work! ❤️
Thank you! 🙂
Thanks mate. Help me a lot.
Happy to help
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?
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.
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.
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.
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?
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.
Thank you so much! This worked.
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!
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!
Thankyou Soooo Muchhh for this video
Helpful! How do I find the most repeated word in my file?
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.
deserved more subs
Src-File ?
Thank you John, 👏👍
Jupyter notebook is great way of working with Pandas - maybe do a vid on that too?
Great idea, I love Jupyter
Great video mate! Take a look at my pandas tutorial if you want.
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)?
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.
@@JohnWatsonRooney thanks for response!
Good one
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 ?
Thanks John
Great!!
thank you
Thanks!!!!
Get video, short and to the point. Now do some guitar tutorials, I'll join you. lol
Haha sure!
Your raw data
Tough British accent