From d1e1fc5c9d637395e32235e45891698478929700 Mon Sep 17 00:00:00 2001 From: Krishna Kaushik <131583096+kRiShNa-429407@users.noreply.github.com> Date: Sat, 18 May 2024 22:37:38 +0530 Subject: [PATCH] Add files via upload --- .../Importing_and_Exporting_Data_in_Pandas.md | 291 ++++++++++++++++++ 1 file changed, 291 insertions(+) create mode 100644 contrib/pandas/Importing_and_Exporting_Data_in_Pandas.md diff --git a/contrib/pandas/Importing_and_Exporting_Data_in_Pandas.md b/contrib/pandas/Importing_and_Exporting_Data_in_Pandas.md new file mode 100644 index 0000000..a6949d2 --- /dev/null +++ b/contrib/pandas/Importing_and_Exporting_Data_in_Pandas.md @@ -0,0 +1,291 @@ +# Importing_and_Exporting_Data_in_Pandas + +>Created by Krishna Kaushik + +- **Now we're able to create `Series` and `DataFrames` in pandas, but we usually do not do this , in practice we import the data which is in the form of .csv (Comma Seperated Values) , a spreadsheet file or something similar.** + +- *Good news is that pandas allows for easy importing of data like this through functions such as ``pd.read_csv()`` and ``pd.read_excel()`` for Microsoft Excel files.* + +## 1. Importing from a Google sheet to a pandas dataframe + +*Let's say that you wanted to get the information from Google Sheet document into a pandas DataFrame.*. + +*You could export it as a .csv file and then import it using ``pd.read_csv()``.* + +*In this case, the exported .csv file is called `Titanic.csv`* + + +```python +## Importing Titanic Data set +import pandas as pd + +titanic_df= pd.read_csv("https://raw.githubusercontent.com/kRiShNa-429407/learn-python/main/contrib/pandas/Titanic.csv") +titanic_df +``` + + + + +
+ | pclass | +survived | +name | +sex | +age | +sibsp | +parch | +ticket | +fare | +cabin | +embarked | +boat | +body | +home.dest | +
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | +1 | +1 | +Allen, Miss. Elisabeth Walton | +female | +29.00 | +0 | +0 | +24160 | +211.3375 | +B5 | +S | +2 | +NaN | +St Louis, MO | +
1 | +1 | +1 | +Allison, Master. Hudson Trevor | +male | +0.92 | +1 | +2 | +113781 | +151.5500 | +C22 C26 | +S | +11 | +NaN | +Montreal, PQ / Chesterville, ON | +
2 | +1 | +0 | +Allison, Miss. Helen Loraine | +female | +2.00 | +1 | +2 | +113781 | +151.5500 | +C22 C26 | +S | +NaN | +NaN | +Montreal, PQ / Chesterville, ON | +
3 | +1 | +0 | +Allison, Mr. Hudson Joshua Creighton | +male | +30.00 | +1 | +2 | +113781 | +151.5500 | +C22 C26 | +S | +NaN | +135.0 | +Montreal, PQ / Chesterville, ON | +
4 | +1 | +0 | +Allison, Mrs. Hudson J C (Bessie Waldo Daniels) | +female | +25.00 | +1 | +2 | +113781 | +151.5500 | +C22 C26 | +S | +NaN | +NaN | +Montreal, PQ / Chesterville, ON | +
... | +... | +... | +... | +... | +... | +... | +... | +... | +... | +... | +... | +... | +... | +... | +
1304 | +3 | +0 | +Zabour, Miss. Hileni | +female | +14.50 | +1 | +0 | +2665 | +14.4542 | +NaN | +C | +NaN | +328.0 | +NaN | +
1305 | +3 | +0 | +Zabour, Miss. Thamine | +female | +NaN | +1 | +0 | +2665 | +14.4542 | +NaN | +C | +NaN | +NaN | +NaN | +
1306 | +3 | +0 | +Zakarian, Mr. Mapriededer | +male | +26.50 | +0 | +0 | +2656 | +7.2250 | +NaN | +C | +NaN | +304.0 | +NaN | +
1307 | +3 | +0 | +Zakarian, Mr. Ortin | +male | +27.00 | +0 | +0 | +2670 | +7.2250 | +NaN | +C | +NaN | +NaN | +NaN | +
1308 | +3 | +0 | +Zimmerman, Mr. Leo | +male | +29.00 | +0 | +0 | +315082 | +7.8750 | +NaN | +S | +NaN | +NaN | +NaN | +
1309 rows × 14 columns
+