Pandas Tutorial
Pandas:
Working with Data sets and Arrays for analyze, clean, and manipulating Data.
Import Pandas:
Coding
Import pandas as pd
Example
Checking pandas version
Coding
import pandas as pd
print(pd.__version__)
This coding used to know about our pandas versions.
Data Frames:
Example 1:
Coding
import pandas as pd
mydataset = { 'TVs': ["Sony", "Samsung", "LG"], 'Passings': [3, 7, 2]
}
myvar = pd.DataFrame(mydataset)
print(myvar)
Output:
Tvs Passings
0 Sony 3
1 Samsung 7
2 LG 2
In this example we set the data's into data frames
pd.DataFrame(mydataset) Used to set data frames
Passings 7
Name: 1, dtype: object
Read CSV File:
We use csv files or excel, sheets for the data analysis.
These files having all the details of the project what we done.
Store big data's into this csv files.
Example:
import pandas as pd
df = pd.read_csv('example.csv')
print(df.to_string())
0 Sony 3
1 Samsung 7
2 LG 2
3 Panasonic 4
4 Mi 6
5 Sansui 5
df = pd.read_json('Example.json')
print(df.to_string())
Output:
0 Sony 3
1 Samsung 7
2 LG 2
3 Panasonic 4
4 Mi 6
df = pd.read_csv('Example.csv')
print(df.head(3))
0 Sony 3
1 Samsung 7
2 LG 2
df = pd.read_csv('Example.csv')
print(df.tail(3))
4 Mi 6
df = pd.read_csv('example.csv')
new_df = df.dropna()
print(new_df.to_string())
dropna() function is used to remove empty cells from our data's.
Wrong format data Correction:
Example:
import pandas as pd
df = pd.read_csv('example.csv')df['Date'] = pd.to_datetime(df['Date'])
print(df.to_string())
Correlation:
df.corr()
this line used to correlate the columns of the datasets.
No comments:
Post a Comment