Skip to content

Commit 0bb8a85

Browse files
authored
Merge branch 'animator:main' into main
2 parents d0e9b35 + 930a906 commit 0bb8a85

File tree

4 files changed

+59
-0
lines changed

4 files changed

+59
-0
lines changed

contrib/pandas/Datasets/car-sales.csv

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Make,Colour,Odometer (KM),Doors,Price
2+
Toyota,White,150043,4,"$4,000.00"
3+
Honda,Red,87899,4,"$5,000.00"
4+
Toyota,Blue,32549,3,"$7,000.00"
5+
BMW,Black,11179,5,"$22,000.00"
6+
Nissan,White,213095,4,"$3,500.00"
7+
Toyota,Green,99213,4,"$4,500.00"
8+
Honda,Blue,45698,4,"$7,500.00"
9+
Honda,Blue,54738,4,"$7,000.00"
10+
Toyota,White,60000,4,"$6,250.00"
11+
Nissan,White,31600,4,"$9,700.00"

contrib/pandas/Datasets/readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
## This folder contains all the Datasets used in the content.

contrib/pandas/import-export.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Importing and Exporting Data in Pandas
2+
3+
## Importing Data from a CSV
4+
5+
We can create `Series` and `DataFrame` in pandas, but often we have to import the data which is in the form of `.csv` (Comma Separated Values), a spreadsheet file or similar tabular data file format.
6+
7+
`pandas` allows for easy importing of this data using functions such as `read_csv()` and `read_excel()` for Microsoft Excel files.
8+
9+
*Note: In case you want to get the information from a **Google Sheet** you can export it as a .csv file.*
10+
11+
The `read_csv()` function can be used to import a CSV file into a pandas DataFrame. The path can be a file system path or a URL where the CSV is available.
12+
13+
```python
14+
import pandas as pd
15+
16+
car_sales_df= pd.read_csv("Datasets/car-sales.csv")
17+
print(car_sales_df)
18+
```
19+
20+
```
21+
Make Colour Odometer (KM) Doors Price
22+
0 Toyota White 150043 4 $4,000.00
23+
1 Honda Red 87899 4 $5,000.00
24+
2 Toyota Blue 32549 3 $7,000.00
25+
3 BMW Black 11179 5 $22,000.00
26+
4 Nissan White 213095 4 $3,500.00
27+
5 Toyota Green 99213 4 $4,500.00
28+
6 Honda Blue 45698 4 $7,500.00
29+
7 Honda Blue 54738 4 $7,000.00
30+
8 Toyota White 60000 4 $6,250.00
31+
9 Nissan White 31600 4 $9,700.00
32+
```
33+
34+
You can find the dataset used above in the `Datasets` folder.
35+
36+
*Note: If you want to import the data from Github you can't directly use its link, you have to first obtain the raw file URL by clicking on the raw button present in the repo*
37+
38+
## Exporting Data to a CSV
39+
40+
`pandas` allows you to export `DataFrame` to `.csv` format using `.to_csv()`, or to a Excel spreadsheet using `.to_excel()`.
41+
42+
```python
43+
car_sales_df.to_csv("exported_car_sales.csv")
44+
```
45+
46+
Running this will save a file called ``exported_car_sales.csv`` to the current folder.

contrib/pandas/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
- [Pandas Descriptive Statistics](Descriptive_Statistics.md)
66
- [Group By Functions with Pandas](GroupBy_Functions_Pandas.md)
77
- [Excel using Pandas DataFrame](excel_with_pandas.md)
8+
- [Importing and Exporting Data in Pandas](import-export.md)

0 commit comments

Comments
 (0)