Skip to content

Commit 255d609

Browse files
Update Importing_and_Exporting_Data_in_Pandas.md
1 parent 5fd2169 commit 255d609

File tree

1 file changed

+17
-46
lines changed

1 file changed

+17
-46
lines changed

contrib/pandas/Importing_and_Exporting_Data_in_Pandas.md

Lines changed: 17 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -12,60 +12,31 @@
1212

1313
*You could export it as a .csv file and then import it using ``pd.read_csv()``.*
1414

15-
*In this case, the exported .csv file is called `Titanic.csv`*
15+
*In this case, the exported .csv file is called `car-sales.csv`*
1616

1717

1818
```python
1919
## Importing Titanic Data set
2020
import pandas as pd
2121

22-
titanic_df= pd.read_csv("https://raw.githubusercontent.com/kRiShNa-429407/learn-python/main/contrib/pandas/Datasets/Titanic.csv")
23-
print(titanic_df)
22+
car_sales_df= pd.read_csv("https://raw.githubusercontent.com/kRiShNa-429407/learn-python/main/contrib/pandas/Datasets/car-sales.csv")
23+
print(car_sales_df)
2424
```
2525

26-
pclass survived name \
27-
0 1 1 Allen, Miss. Elisabeth Walton
28-
1 1 1 Allison, Master. Hudson Trevor
29-
2 1 0 Allison, Miss. Helen Loraine
30-
3 1 0 Allison, Mr. Hudson Joshua Creighton
31-
4 1 0 Allison, Mrs. Hudson J C (Bessie Waldo Daniels)
32-
... ... ... ...
33-
1304 3 0 Zabour, Miss. Hileni
34-
1305 3 0 Zabour, Miss. Thamine
35-
1306 3 0 Zakarian, Mr. Mapriededer
36-
1307 3 0 Zakarian, Mr. Ortin
37-
1308 3 0 Zimmerman, Mr. Leo
38-
39-
sex age sibsp parch ticket fare cabin embarked boat \
40-
0 female 29.00 0 0 24160 211.3375 B5 S 2
41-
1 male 0.92 1 2 113781 151.5500 C22 C26 S 11
42-
2 female 2.00 1 2 113781 151.5500 C22 C26 S NaN
43-
3 male 30.00 1 2 113781 151.5500 C22 C26 S NaN
44-
4 female 25.00 1 2 113781 151.5500 C22 C26 S NaN
45-
... ... ... ... ... ... ... ... ... ...
46-
1304 female 14.50 1 0 2665 14.4542 NaN C NaN
47-
1305 female NaN 1 0 2665 14.4542 NaN C NaN
48-
1306 male 26.50 0 0 2656 7.2250 NaN C NaN
49-
1307 male 27.00 0 0 2670 7.2250 NaN C NaN
50-
1308 male 29.00 0 0 315082 7.8750 NaN S NaN
51-
52-
body home.dest
53-
0 NaN St Louis, MO
54-
1 NaN Montreal, PQ / Chesterville, ON
55-
2 NaN Montreal, PQ / Chesterville, ON
56-
3 135.0 Montreal, PQ / Chesterville, ON
57-
4 NaN Montreal, PQ / Chesterville, ON
58-
... ... ...
59-
1304 328.0 NaN
60-
1305 NaN NaN
61-
1306 304.0 NaN
62-
1307 NaN NaN
63-
1308 NaN NaN
64-
65-
[1309 rows x 14 columns]
26+
Make Colour Odometer (KM) Doors Price
27+
0 Toyota White 150043 4 $4,000.00
28+
1 Honda Red 87899 4 $5,000.00
29+
2 Toyota Blue 32549 3 $7,000.00
30+
3 BMW Black 11179 5 $22,000.00
31+
4 Nissan White 213095 4 $3,500.00
32+
5 Toyota Green 99213 4 $4,500.00
33+
6 Honda Blue 45698 4 $7,500.00
34+
7 Honda Blue 54738 4 $7,000.00
35+
8 Toyota White 60000 4 $6,250.00
36+
9 Nissan White 31600 4 $9,700.00
6637

6738

68-
The dataset I am using here for your reference is taken from the same repository i.e ``learn-python`` (https://raw.githubusercontent.com/kRiShNa-429407/learn-python/main/contrib/pandas/Datasets/Titanic.csv) I uploaded it in the Datasets folder,you can use it from there.
39+
The dataset I am using here for your reference is taken from the same repository i.e ``learn-python`` (https://raw.githubusercontent.com/kRiShNa-429407/learn-python/main/contrib/pandas/Datasets/car-sales.csv) I uploaded it in the Datasets folder,you can use it from there.
6940

7041
You can also place the filename with its path in `pd.read_csv()`.
7142

@@ -92,12 +63,12 @@ You can also place the filename with its path in `pd.read_csv()`.
9263

9364
### Exporting a dataframe to a CSV
9465

95-
**We haven't made any changes yet to the ``titanic_df`` DataFrame but let's try to export it.**
66+
**We haven't made any changes yet to the ``car_sales_df`` DataFrame but let's try to export it.**
9667

9768

9869
```python
9970
#Export the titanic_df DataFrame to csv
100-
titanic_df.to_csv("exported_titanic.csv")
71+
car_sales_df.to_csv("exported_car_sales_df.csv")
10172
```
10273

10374
Running this will save a file called ``exported_titanic.csv`` to the current folder.

0 commit comments

Comments
 (0)