In this video you will see how easy it is to read and write to and from csv files in Python. We will use Jupyter Notebooks and use pandas primarily. As with all videos on Tech Know How, we will walk through all of the code.
First we load the pandas library. Then we pull the data from a local csv file. This example uses public data for mispriced diamonds. Next we use matplotlib to create a scatter plot of the data and we use price and carat size. Then we will add a real business use case and add to the data before we right it to a new csv file (you don't want to update the original file as that is how you can corrupt the data - always create a new file).
So, then we decide we are going to implement a 20% price reduction on all diamonds. So we will need 2 new columns - one for the new price and the second for the amount of the price reduction. Then I show exactly how to create these new columns with the correct data calculated .
df['New Column1'] = df["OldColumn'] * calculated percentage
Then we go and get the average and the total amount of price reduction.
After this we then right the data with the 2 new columns back to a new CSV file.
This is a complete walk through with a little exploratory data analysis. Data science and analytics can be interesting if you let it.
Thank you for watching this python write to csv file video. Please take a moment to subscribe, like and share so that others may benefit same as you.
Thanks again and God bless!
![](https://s2.save4k.ru/pic/QyEotZGTi4w/mqdefault.jpg)