Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update pandas.md #50

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion python/data-science/pandas.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Pandas is a very powerful library which has many features to help data scientist

## What is a DataFrame

A DataFrame is a two-dimensional data structure means the data is aligned into rows and columns. DataFrames are the standard way to store the data. They are size-mutable, potentially heterogeneous tabular data.
A DataFrame is a two-dimensional data structure, means the data is aligned into rows and columns. DataFrames are the standard way to store the data. They are size-mutable, potentially heterogeneous tabular data.

## How to create DataFrame

Expand Down Expand Up @@ -58,5 +58,31 @@ data = pd.read_csv('example.csv') # reads example.csv csv file

print(data)
```
### import from excel files

You can also import csv files to create DataFrames. Consider you have example.csv stored and can be imported using Pandas using pd.read_csv().

```py
import pandas as pd

data = pd.read_excel('example.xlsx') # reads example.xlsx xlsx file

print(data)
```
### dropping a column
you can drop a column using drop() method

```py
import pandas as pd
dict1 = {"country": ["USA", "Mexico", "India", "Australia","China", "Indonesia"],
"language": ["English", "spanish", "Hindi", "English", "Chinese", "Indonesian"]}

df = pd.DataFrame(dict)
df.drop("country",axis=1)
```
### exporting a dataframe to csv
you can export a dataframe to csv file using to_csv() method

```py
df.to_csv("output.csv")
```