Skip to main content

Data Preprocessing

Working with data

This is a demo file for Data Preprocessing [Working with Data]

How to read data from .csv file

In [8]:
import pandas as pd
df = pd.read_csv("weather_data.csv")
df
Out[8]:
day temperature windspeed event
0 1/1/2017 32 6 Rain
1 1/2/2017 35 7 Sunny
2 1/3/2017 28 2 Snow

Reading .xlsx file

In [12]:
df=pd.read_excel("weather_data.xlsx","demo")
df
Out[12]:
day temperature windspeed event
0 2017-01-01 32 6 Rain
1 2017-01-02 35 7 Sunny
2 2017-01-03 28 2 Snow

Using dictionary

In [14]:
import pandas as pd
weather_data = {
    'day': ['1/1/2017','1/2/2017','1/3/2017'],
    'temperature': [32,35,28],
    'windspeed': [6,7,2],
    'event': ['Rain', 'Sunny', 'Snow']
}
df = pd.DataFrame(weather_data)
df
Out[14]:
day temperature windspeed event
0 1/1/2017 32 6 Rain
1 1/2/2017 35 7 Sunny
2 1/3/2017 28 2 Snow

Using tuples list

In [15]:
weather_data = [
    ('1/1/2017',32,6,'Rain'),
    ('1/2/2017',35,7,'Sunny'),
    ('1/3/2017',28,2,'Snow')
]
df = pd.DataFrame(data=weather_data, columns=['day','temperature','windspeed','event'])
df
Out[15]:
day temperature windspeed event
0 1/1/2017 32 6 Rain
1 1/2/2017 35 7 Sunny
2 1/3/2017 28 2 Snow

Using list of dictionaries

In [17]:
weather_data = [
    {'day': '1/1/2017', 'temperature': 32, 'windspeed': 6, 'event': 'Rain'},
    {'day': '1/2/2017', 'temperature': 35, 'windspeed': 7, 'event': 'Sunny'},
    {'day': '1/3/2017', 'temperature': 28, 'windspeed': 2, 'event': 'Snow'},
    
]
df = pd.DataFrame(data=weather_data, columns=['day','temperature','windspeed','event'])
df
Out[17]:
day temperature windspeed event
0 1/1/2017 32 6 Rain
1 1/2/2017 35 7 Sunny
2 1/3/2017 28 2 Snow
In [ ]:
 

Comments

Post a Comment

Popular posts from this blog

Theory of Computaion

Give the answer of the following questions: What is principle of mathematical induction? Explain types of it. Also what is need of those PM’s'? What do you understand by strong principle of mathematical induction? How it is different from mathematical induction? Give an example of a statement where you require strong principle of mathematical induction. Prove the following using weak pmi: Prove that integer bigger than 2 have prime factorization. Define: The principle of mathematical induction. Also prove for any string x and n>=0 REV (xy) =REV(y) REV(x). Strong PMI: Suppose p(n) is a statement involving an integer n, then to prove that p(n) is true for every n>= n 0 it is sufficient to show two thing. P(n 0 ) is true For any k>=n 0 , if p (n) is true, for every n satisfying n 0 <=n<=k then p (k+1) is true. Prove the following using strong pmi: For any n>=2, n is either prime or product...