0% found this document useful (0 votes)
123 views

Latihan Python

The document describes troubleshooting errors when importing a CSV file into a Pandas dataframe in Python. It shows several attempts to import the file that result in a SyntaxError due to an invalid path. The valid path is specified using double backslashes, and the CSV is successfully read into a dataframe. Some basic operations on the dataframe are then demonstrated, such as finding the maximum temperature and filtering rows where the "Events" column equals "Rain".

Uploaded by

achmad_bahauddin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
123 views

Latihan Python

The document describes troubleshooting errors when importing a CSV file into a Pandas dataframe in Python. It shows several attempts to import the file that result in a SyntaxError due to an invalid path. The valid path is specified using double backslashes, and the CSV is successfully read into a dataframe. Some basic operations on the dataframe are then demonstrated, such as finding the maximum temperature and filtering rows where the "Events" column equals "Rain".

Uploaded by

achmad_bahauddin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

10/2/2018 Untitled1

In [1]: import pandas as pd


df = pd.read_csv('C:\Users\user\Documents\Python_Scripts\nyc_weather.csv')
df

File "<ipython-input-1-51c02fab5e1d>", line 2


df = pd.read_csv('C:\Users\user\Documents\Python_Scripts\nyc_weather.csv')
^
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape

In [2]: import pandas as pd


df = pd.read_csv('C:\Users\user\Documents\Python Scripts\nyc_weather.csv')
df

File "<ipython-input-2-d401b0f8efd9>", line 2


df = pd.read_csv('C:\Users\user\Documents\Python Scripts\nyc_weather.csv')
^
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape

In [3]: import pandas as pd


df = pd.read_csv('C:\Users\user\Documents\nyc_weather.csv')
df

File "<ipython-input-3-08ab4f34fd4c>", line 2


df = pd.read_csv('C:\Users\user\Documents\nyc_weather.csv')
^
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape

http://localhost:8888/nbconvert/html/Untitled1.ipynb?download=false 1/15
10/2/2018 Untitled1

In [4]: import pandas as pd


df = pd.read_csv('C:\\Users\\user\\Documents\\nyc_weather.csv')
df

Out[4]:
EST Temperature DewPoint Humidity Sea Level PressureIn VisibilityMiles WindSpeedMPH PrecipitationIn CloudCover Events WindDirDegrees Unnamed: 11

0 01-01-16 38 23 52 30.03 10 8.0 0 5 NaN 281 NaN

1 01-02-16 36 18 46 30.02 10 7.0 0 3 NaN 275 NaN

2 01-03-16 40 21 47 29.86 10 8.0 0 1 NaN 277 NaN

3 01-04-16 25 9 44 30.05 10 9.0 0 3 NaN 345 NaN

4 01-05-16 20 -3 41 30.57 10 5.0 0 0 NaN 333 NaN

5 01-06-16 33 4 35 30.50 10 4.0 0 0 NaN 259 NaN

6 01-07-16 39 11 33 30.28 10 2.0 0 3 NaN 293 NaN

7 01-08-16 39 29 64 30.20 10 4.0 0 8 NaN 79 NaN

8 01-09-16 44 38 77 30.16 9 8.0 T 8 Rain 76 NaN

9 01-10-16 50 46 71 29.59 4 NaN 1.8 7 Rain 109 NaN

10 01-11-16 33 8 37 29.92 10 NaN 0 1 NaN 289 NaN

11 01-12-16 35 15 53 29.85 10 6.0 T 4 NaN 235 NaN

12 1/13/2016 26 4 42 29.94 10 10.0 0 0 NaN 284 NaN

13 1/14/2016 30 12 47 29.95 10 5.0 T 7 NaN 266 NaN

14 1/15/2016 43 31 62 29.82 9 5.0 T 2 NaN 101 NaN

15 1/16/2016 47 37 70 29.52 8 7.0 0.24 7 Rain 340 NaN

16 1/17/2016 36 23 66 29.78 8 6.0 0.05 6 Fog-Snow 345 NaN

17 1/18/2016 25 6 53 29.83 9 12.0 T 2 Snow 293 NaN

18 1/19/2016 22 3 42 30.03 10 11.0 0 1 NaN 293 NaN

19 1/20/2016 32 15 49 30.13 10 6.0 0 2 NaN 302 NaN

20 1/21/2016 31 11 45 30.15 10 6.0 0 1 NaN 312 NaN

21 1/22/2016 26 6 41 30.21 9 NaN 0.01 3 Snow 34 NaN

22 1/23/2016 26 21 78 29.77 1 16.0 2.31 8 Fog-Snow 42 NaN

23 1/24/2016 28 11 53 29.92 8 6.0 T 3 Snow 327 NaN

24 1/25/2016 34 18 54 30.25 10 3.0 0 2 NaN 286 NaN

25 1/26/2016 43 29 56 30.03 10 7.0 0 2 NaN 244 NaN

26 1/27/2016 41 22 45 30.03 10 7.0 T 3 Rain 311 NaN

27 1/28/2016 37 20 51 29.90 10 5.0 0 1 NaN 234 NaN

28 1/29/2016 36 21 50 29.58 10 8.0 0 4 NaN 298 NaN

29 1/30/2016 34 16 46 30.01 10 7.0 0 0 NaN 257 NaN

30 1/31/2016 46 28 52 29.90 10 5.0 0 0 NaN 241 NaN

In [5]: df['Temperature'].max()

Out[5]: 50

In [6]: df['EST'][df['Events']=='Rain']

Out[6]: 8 01-09-16
9 01-10-16
15 1/16/2016
26 1/27/2016
Name: EST, dtype: object

http://localhost:8888/nbconvert/html/Untitled1.ipynb?download=false 2/15
10/2/2018 Untitled1

In [7]: df.head()

Out[7]:
EST Temperature DewPoint Humidity Sea Level PressureIn VisibilityMiles WindSpeedMPH PrecipitationIn CloudCover Events WindDirDegrees Unnamed: 11

0 01-01-16 38 23 52 30.03 10 8.0 0 5 NaN 281 NaN

1 01-02-16 36 18 46 30.02 10 7.0 0 3 NaN 275 NaN

2 01-03-16 40 21 47 29.86 10 8.0 0 1 NaN 277 NaN

3 01-04-16 25 9 44 30.05 10 9.0 0 3 NaN 345 NaN

4 01-05-16 20 -3 41 30.57 10 5.0 0 0 NaN 333 NaN

In [8]: df.tail()

Out[8]:
EST Temperature DewPoint Humidity Sea Level PressureIn VisibilityMiles WindSpeedMPH PrecipitationIn CloudCover Events WindDirDegrees Unnamed: 11

26 1/27/2016 41 22 45 30.03 10 7.0 T 3 Rain 311 NaN

27 1/28/2016 37 20 51 29.90 10 5.0 0 1 NaN 234 NaN

28 1/29/2016 36 21 50 29.58 10 8.0 0 4 NaN 298 NaN

29 1/30/2016 34 16 46 30.01 10 7.0 0 0 NaN 257 NaN

30 1/31/2016 46 28 52 29.90 10 5.0 0 0 NaN 241 NaN

In [9]: Temp = df['Temperature']

In [10]: Temp

Out[10]: 0 38
1 36
2 40
3 25
4 20
5 33
6 39
7 39
8 44
9 50
10 33
11 35
12 26
13 30
14 43
15 47
16 36
17 25
18 22
19 32
20 31
21 26
22 26
23 28
24 34
25 43
26 41
27 37
28 36
29 34
30 46
Name: Temperature, dtype: int64

http://localhost:8888/nbconvert/html/Untitled1.ipynb?download=false 3/15
10/2/2018 Untitled1

In [11]: df = pd.read_csv('C:\\Users\\user\\Documents\\nyc_weather.csv', index_col='EST', parse_dates=True)


df

Out[11]:
Temperature DewPoint Humidity Sea Level PressureIn VisibilityMiles WindSpeedMPH PrecipitationIn CloudCover Events WindDirDegrees Unnamed: 11

EST

2016-01-01 38 23 52 30.03 10 8.0 0 5 NaN 281 NaN

2016-01-02 36 18 46 30.02 10 7.0 0 3 NaN 275 NaN

2016-01-03 40 21 47 29.86 10 8.0 0 1 NaN 277 NaN

2016-01-04 25 9 44 30.05 10 9.0 0 3 NaN 345 NaN

2016-01-05 20 -3 41 30.57 10 5.0 0 0 NaN 333 NaN

2016-01-06 33 4 35 30.50 10 4.0 0 0 NaN 259 NaN

2016-01-07 39 11 33 30.28 10 2.0 0 3 NaN 293 NaN

2016-01-08 39 29 64 30.20 10 4.0 0 8 NaN 79 NaN

2016-01-09 44 38 77 30.16 9 8.0 T 8 Rain 76 NaN

2016-01-10 50 46 71 29.59 4 NaN 1.8 7 Rain 109 NaN

2016-01-11 33 8 37 29.92 10 NaN 0 1 NaN 289 NaN

2016-01-12 35 15 53 29.85 10 6.0 T 4 NaN 235 NaN

2016-01-13 26 4 42 29.94 10 10.0 0 0 NaN 284 NaN

2016-01-14 30 12 47 29.95 10 5.0 T 7 NaN 266 NaN

2016-01-15 43 31 62 29.82 9 5.0 T 2 NaN 101 NaN

2016-01-16 47 37 70 29.52 8 7.0 0.24 7 Rain 340 NaN

2016-01-17 36 23 66 29.78 8 6.0 0.05 6 Fog-Snow 345 NaN

2016-01-18 25 6 53 29.83 9 12.0 T 2 Snow 293 NaN

2016-01-19 22 3 42 30.03 10 11.0 0 1 NaN 293 NaN

2016-01-20 32 15 49 30.13 10 6.0 0 2 NaN 302 NaN

2016-01-21 31 11 45 30.15 10 6.0 0 1 NaN 312 NaN

2016-01-22 26 6 41 30.21 9 NaN 0.01 3 Snow 34 NaN

2016-01-23 26 21 78 29.77 1 16.0 2.31 8 Fog-Snow 42 NaN

2016-01-24 28 11 53 29.92 8 6.0 T 3 Snow 327 NaN

2016-01-25 34 18 54 30.25 10 3.0 0 2 NaN 286 NaN

2016-01-26 43 29 56 30.03 10 7.0 0 2 NaN 244 NaN

2016-01-27 41 22 45 30.03 10 7.0 T 3 Rain 311 NaN

2016-01-28 37 20 51 29.90 10 5.0 0 1 NaN 234 NaN

2016-01-29 36 21 50 29.58 10 8.0 0 4 NaN 298 NaN

2016-01-30 34 16 46 30.01 10 7.0 0 0 NaN 257 NaN

2016-01-31 46 28 52 29.90 10 5.0 0 0 NaN 241 NaN

http://localhost:8888/nbconvert/html/Untitled1.ipynb?download=false 4/15
10/2/2018 Untitled1

In [12]: Temp

Out[12]: 0 38
1 36
2 40
3 25
4 20
5 33
6 39
7 39
8 44
9 50
10 33
11 35
12 26
13 30
14 43
15 47
16 36
17 25
18 22
19 32
20 31
21 26
22 26
23 28
24 34
25 43
26 41
27 37
28 36
29 34
30 46
Name: Temperature, dtype: int64

In [13]: temp=df['EST']df['Temperature']
temp

File "<ipython-input-13-085165785fa6>", line 1


temp=df['EST']df['Temperature']
^
SyntaxError: invalid syntax

http://localhost:8888/nbconvert/html/Untitled1.ipynb?download=false 5/15
10/2/2018 Untitled1

In [14]: temp=df['EST'][df['Temperature']]
temp

---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
~\Anaconda3\lib\site-packages\pandas\core\indexes\base.py in get_loc(self, key, method, tolerance)
3062 try:
-> 3063 return self._engine.get_loc(key)
3064 except KeyError:

pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas\_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

pandas\_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

KeyError: 'EST'

During handling of the above exception, another exception occurred:

KeyError Traceback (most recent call last)


<ipython-input-14-765fe46f09f1> in <module>()
----> 1 temp=df['EST'][df['Temperature']]
2 temp

~\Anaconda3\lib\site-packages\pandas\core\frame.py in __getitem__(self, key)


2683 return self._getitem_multilevel(key)
2684 else:
-> 2685 return self._getitem_column(key)
2686
2687 def _getitem_column(self, key):

~\Anaconda3\lib\site-packages\pandas\core\frame.py in _getitem_column(self, key)


2690 # get column
2691 if self.columns.is_unique:
-> 2692 return self._get_item_cache(key)
2693
2694 # duplicate columns & possible reduce dimensionality

~\Anaconda3\lib\site-packages\pandas\core\generic.py in _get_item_cache(self, item)


2484 res = cache.get(item)
2485 if res is None:
-> 2486 values = self._data.get(item)
2487 res = self._box_item_values(item, values)
2488 cache[item] = res

~\Anaconda3\lib\site-packages\pandas\core\internals.py in get(self, item, fastpath)


4113
4114 if not isna(item):
-> 4115 loc = self.items.get_loc(item)
4116 else:
4117 indexer = np.arange(len(self.items))[isna(self.items)]

~\Anaconda3\lib\site-packages\pandas\core\indexes\base.py in get_loc(self, key, method, tolerance)


3063 return self._engine.get_loc(key)
3064 except KeyError:
-> 3065 return self._engine.get_loc(self._maybe_cast_indexer(key))
3066
3067 indexer = self.get_indexer([key], method=method, tolerance=tolerance)

pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas\_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

pandas\_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

KeyError: 'EST'

http://localhost:8888/nbconvert/html/Untitled1.ipynb?download=false 6/15
10/2/2018 Untitled1

In [15]: df['EST']

---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
~\Anaconda3\lib\site-packages\pandas\core\indexes\base.py in get_loc(self, key, method, tolerance)
3062 try:
-> 3063 return self._engine.get_loc(key)
3064 except KeyError:

pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas\_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

pandas\_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

KeyError: 'EST'

During handling of the above exception, another exception occurred:

KeyError Traceback (most recent call last)


<ipython-input-15-566303c2023e> in <module>()
----> 1 df['EST']

~\Anaconda3\lib\site-packages\pandas\core\frame.py in __getitem__(self, key)


2683 return self._getitem_multilevel(key)
2684 else:
-> 2685 return self._getitem_column(key)
2686
2687 def _getitem_column(self, key):

~\Anaconda3\lib\site-packages\pandas\core\frame.py in _getitem_column(self, key)


2690 # get column
2691 if self.columns.is_unique:
-> 2692 return self._get_item_cache(key)
2693
2694 # duplicate columns & possible reduce dimensionality

~\Anaconda3\lib\site-packages\pandas\core\generic.py in _get_item_cache(self, item)


2484 res = cache.get(item)
2485 if res is None:
-> 2486 values = self._data.get(item)
2487 res = self._box_item_values(item, values)
2488 cache[item] = res

~\Anaconda3\lib\site-packages\pandas\core\internals.py in get(self, item, fastpath)


4113
4114 if not isna(item):
-> 4115 loc = self.items.get_loc(item)
4116 else:
4117 indexer = np.arange(len(self.items))[isna(self.items)]

~\Anaconda3\lib\site-packages\pandas\core\indexes\base.py in get_loc(self, key, method, tolerance)


3063 return self._engine.get_loc(key)
3064 except KeyError:
-> 3065 return self._engine.get_loc(self._maybe_cast_indexer(key))
3066
3067 indexer = self.get_indexer([key], method=method, tolerance=tolerance)

pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas\_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

pandas\_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

KeyError: 'EST'

http://localhost:8888/nbconvert/html/Untitled1.ipynb?download=false 7/15
10/2/2018 Untitled1

In [16]: df = pd.read_csv('C:\\Users\\user\\Documents\\nyc_weather.csv', index_col='EST', parse_dates=True)


df

Out[16]:
Temperature DewPoint Humidity Sea Level PressureIn VisibilityMiles WindSpeedMPH PrecipitationIn CloudCover Events WindDirDegrees Unnamed: 11

EST

2016-01-01 38 23 52 30.03 10 8.0 0 5 NaN 281 NaN

2016-01-02 36 18 46 30.02 10 7.0 0 3 NaN 275 NaN

2016-01-03 40 21 47 29.86 10 8.0 0 1 NaN 277 NaN

2016-01-04 25 9 44 30.05 10 9.0 0 3 NaN 345 NaN

2016-01-05 20 -3 41 30.57 10 5.0 0 0 NaN 333 NaN

2016-01-06 33 4 35 30.50 10 4.0 0 0 NaN 259 NaN

2016-01-07 39 11 33 30.28 10 2.0 0 3 NaN 293 NaN

2016-01-08 39 29 64 30.20 10 4.0 0 8 NaN 79 NaN

2016-01-09 44 38 77 30.16 9 8.0 T 8 Rain 76 NaN

2016-01-10 50 46 71 29.59 4 NaN 1.8 7 Rain 109 NaN

2016-01-11 33 8 37 29.92 10 NaN 0 1 NaN 289 NaN

2016-01-12 35 15 53 29.85 10 6.0 T 4 NaN 235 NaN

2016-01-13 26 4 42 29.94 10 10.0 0 0 NaN 284 NaN

2016-01-14 30 12 47 29.95 10 5.0 T 7 NaN 266 NaN

2016-01-15 43 31 62 29.82 9 5.0 T 2 NaN 101 NaN

2016-01-16 47 37 70 29.52 8 7.0 0.24 7 Rain 340 NaN

2016-01-17 36 23 66 29.78 8 6.0 0.05 6 Fog-Snow 345 NaN

2016-01-18 25 6 53 29.83 9 12.0 T 2 Snow 293 NaN

2016-01-19 22 3 42 30.03 10 11.0 0 1 NaN 293 NaN

2016-01-20 32 15 49 30.13 10 6.0 0 2 NaN 302 NaN

2016-01-21 31 11 45 30.15 10 6.0 0 1 NaN 312 NaN

2016-01-22 26 6 41 30.21 9 NaN 0.01 3 Snow 34 NaN

2016-01-23 26 21 78 29.77 1 16.0 2.31 8 Fog-Snow 42 NaN

2016-01-24 28 11 53 29.92 8 6.0 T 3 Snow 327 NaN

2016-01-25 34 18 54 30.25 10 3.0 0 2 NaN 286 NaN

2016-01-26 43 29 56 30.03 10 7.0 0 2 NaN 244 NaN

2016-01-27 41 22 45 30.03 10 7.0 T 3 Rain 311 NaN

2016-01-28 37 20 51 29.90 10 5.0 0 1 NaN 234 NaN

2016-01-29 36 21 50 29.58 10 8.0 0 4 NaN 298 NaN

2016-01-30 34 16 46 30.01 10 7.0 0 0 NaN 257 NaN

2016-01-31 46 28 52 29.90 10 5.0 0 0 NaN 241 NaN

http://localhost:8888/nbconvert/html/Untitled1.ipynb?download=false 8/15
10/2/2018 Untitled1

In [17]: df = pd.read_csv('C:\\Users\\user\\Documents\\nyc_weather.csv', index_col='EST', parse_dates=['EST'])


df

Out[17]:
Temperature DewPoint Humidity Sea Level PressureIn VisibilityMiles WindSpeedMPH PrecipitationIn CloudCover Events WindDirDegrees Unnamed: 11

EST

2016-01-01 38 23 52 30.03 10 8.0 0 5 NaN 281 NaN

2016-01-02 36 18 46 30.02 10 7.0 0 3 NaN 275 NaN

2016-01-03 40 21 47 29.86 10 8.0 0 1 NaN 277 NaN

2016-01-04 25 9 44 30.05 10 9.0 0 3 NaN 345 NaN

2016-01-05 20 -3 41 30.57 10 5.0 0 0 NaN 333 NaN

2016-01-06 33 4 35 30.50 10 4.0 0 0 NaN 259 NaN

2016-01-07 39 11 33 30.28 10 2.0 0 3 NaN 293 NaN

2016-01-08 39 29 64 30.20 10 4.0 0 8 NaN 79 NaN

2016-01-09 44 38 77 30.16 9 8.0 T 8 Rain 76 NaN

2016-01-10 50 46 71 29.59 4 NaN 1.8 7 Rain 109 NaN

2016-01-11 33 8 37 29.92 10 NaN 0 1 NaN 289 NaN

2016-01-12 35 15 53 29.85 10 6.0 T 4 NaN 235 NaN

2016-01-13 26 4 42 29.94 10 10.0 0 0 NaN 284 NaN

2016-01-14 30 12 47 29.95 10 5.0 T 7 NaN 266 NaN

2016-01-15 43 31 62 29.82 9 5.0 T 2 NaN 101 NaN

2016-01-16 47 37 70 29.52 8 7.0 0.24 7 Rain 340 NaN

2016-01-17 36 23 66 29.78 8 6.0 0.05 6 Fog-Snow 345 NaN

2016-01-18 25 6 53 29.83 9 12.0 T 2 Snow 293 NaN

2016-01-19 22 3 42 30.03 10 11.0 0 1 NaN 293 NaN

2016-01-20 32 15 49 30.13 10 6.0 0 2 NaN 302 NaN

2016-01-21 31 11 45 30.15 10 6.0 0 1 NaN 312 NaN

2016-01-22 26 6 41 30.21 9 NaN 0.01 3 Snow 34 NaN

2016-01-23 26 21 78 29.77 1 16.0 2.31 8 Fog-Snow 42 NaN

2016-01-24 28 11 53 29.92 8 6.0 T 3 Snow 327 NaN

2016-01-25 34 18 54 30.25 10 3.0 0 2 NaN 286 NaN

2016-01-26 43 29 56 30.03 10 7.0 0 2 NaN 244 NaN

2016-01-27 41 22 45 30.03 10 7.0 T 3 Rain 311 NaN

2016-01-28 37 20 51 29.90 10 5.0 0 1 NaN 234 NaN

2016-01-29 36 21 50 29.58 10 8.0 0 4 NaN 298 NaN

2016-01-30 34 16 46 30.01 10 7.0 0 0 NaN 257 NaN

2016-01-31 46 28 52 29.90 10 5.0 0 0 NaN 241 NaN

http://localhost:8888/nbconvert/html/Untitled1.ipynb?download=false 9/15
10/2/2018 Untitled1

In [18]: dt = df['Temperature']
dt

Out[18]: EST
2016-01-01 38
2016-01-02 36
2016-01-03 40
2016-01-04 25
2016-01-05 20
2016-01-06 33
2016-01-07 39
2016-01-08 39
2016-01-09 44
2016-01-10 50
2016-01-11 33
2016-01-12 35
2016-01-13 26
2016-01-14 30
2016-01-15 43
2016-01-16 47
2016-01-17 36
2016-01-18 25
2016-01-19 22
2016-01-20 32
2016-01-21 31
2016-01-22 26
2016-01-23 26
2016-01-24 28
2016-01-25 34
2016-01-26 43
2016-01-27 41
2016-01-28 37
2016-01-29 36
2016-01-30 34
2016-01-31 46
Name: Temperature, dtype: int64

In [19]: dt=dt.sort_index(ascending=True)

http://localhost:8888/nbconvert/html/Untitled1.ipynb?download=false 10/15
10/2/2018 Untitled1

In [20]: dt

Out[20]: EST
2016-01-01 38
2016-01-02 36
2016-01-03 40
2016-01-04 25
2016-01-05 20
2016-01-06 33
2016-01-07 39
2016-01-08 39
2016-01-09 44
2016-01-10 50
2016-01-11 33
2016-01-12 35
2016-01-13 26
2016-01-14 30
2016-01-15 43
2016-01-16 47
2016-01-17 36
2016-01-18 25
2016-01-19 22
2016-01-20 32
2016-01-21 31
2016-01-22 26
2016-01-23 26
2016-01-24 28
2016-01-25 34
2016-01-26 43
2016-01-27 41
2016-01-28 37
2016-01-29 36
2016-01-30 34
2016-01-31 46
Name: Temperature, dtype: int64

In [21]: dt=dt.sort_index(descending=True)

---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-21-9954d923f2ab> in <module>()
----> 1 dt=dt.sort_index(descending=True)

TypeError: sort_index() got an unexpected keyword argument 'descending'

http://localhost:8888/nbconvert/html/Untitled1.ipynb?download=false 11/15
10/2/2018 Untitled1

In [22]: dt

Out[22]: EST
2016-01-01 38
2016-01-02 36
2016-01-03 40
2016-01-04 25
2016-01-05 20
2016-01-06 33
2016-01-07 39
2016-01-08 39
2016-01-09 44
2016-01-10 50
2016-01-11 33
2016-01-12 35
2016-01-13 26
2016-01-14 30
2016-01-15 43
2016-01-16 47
2016-01-17 36
2016-01-18 25
2016-01-19 22
2016-01-20 32
2016-01-21 31
2016-01-22 26
2016-01-23 26
2016-01-24 28
2016-01-25 34
2016-01-26 43
2016-01-27 41
2016-01-28 37
2016-01-29 36
2016-01-30 34
2016-01-31 46
Name: Temperature, dtype: int64

In [23]: dt.plot(label='Temp')

Out[23]: <matplotlib.axes._subplots.AxesSubplot at 0x47c49b0>

In [24]: plt.legend()

---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-24-a140b03f3a4c> in <module>()
----> 1 plt.legend()

NameError: name 'plt' is not defined

In [25]: import matplotlib.pyplot as plt

In [26]: plt.legend()

No handles with labels found to put in legend.


Out[26]: <matplotlib.legend.Legend at 0x8c92160>

http://localhost:8888/nbconvert/html/Untitled1.ipynb?download=false 12/15
10/2/2018 Untitled1

In [27]: dt.plot(label='Temp')

Out[27]: <matplotlib.axes._subplots.AxesSubplot at 0x8e7ab00>

In [28]: plt.show()

In [29]: mavg=pd.roll

---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-29-77fe202408bd> in <module>()
----> 1 mavg=pd.roll

AttributeError: module 'pandas' has no attribute 'roll'

In [30]: plt.plot(dt)

Out[30]: [<matplotlib.lines.Line2D at 0x91d5ba8>]

In [31]: data_log = np.log(dt)

---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-31-390c8a7895fb> in <module>()
----> 1 data_log = np.log(dt)

NameError: name 'np' is not defined

In [32]: import numpy as np

In [33]: data_log = np.log(dt)

In [34]: Ddata_log = data_log - data_log.shift()

http://localhost:8888/nbconvert/html/Untitled1.ipynb?download=false 13/15
10/2/2018 Untitled1

In [35]: plt.plot(Ddata_log)

Out[35]: [<matplotlib.lines.Line2D at 0xa80d588>]

In [36]: series = Ddata_log.fillna(value=Ddata_log.mean(), inplace=False)

In [37]: plot_acf(series,alpha =.05, lags=31)

---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-37-3fff420e0e3a> in <module>()
----> 1 plot_acf(series,alpha =.05, lags=31)

NameError: name 'plot_acf' is not defined

In [38]: plot.acf(series,alpha =.05, lags=31)

---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-38-e5c07eb1dde7> in <module>()
----> 1 plot.acf(series,alpha =.05, lags=31)

NameError: name 'plot' is not defined

In [40]: from statsmodels.graphics.tsaplots import plot_acf, plot_pacf


C:\Users\user\Anaconda3\Lib\site-packages\statsmodels\compat\pandas.py

File "<ipython-input-40-e24fcdfac2a1>", line 2


C:\Users\user\Anaconda3\Lib\site-packages\statsmodels\compat\pandas.py
^
SyntaxError: unexpected character after line continuation character

In [41]: from statsmodels.graphics.tsaplots import plot_acf, plot_pacf


C:\\Users\\user\\Anaconda3\\Lib\\site-packages\\statsmodels\\compat\\pandas.py

File "<ipython-input-41-35dfafbadf29>", line 2


C:\\Users\\user\\Anaconda3\\Lib\\site-packages\\statsmodels\\compat\\pandas.py
^
SyntaxError: unexpected character after line continuation character

In [42]: from statsmodels.graphics.tsaplots import plot_acf, plot_pacf


C:\\Users\\user\\Anaconda3\\Lib\\site-packages\\statsmodels\\compat\\pandas

File "<ipython-input-42-cfa4ace92b45>", line 2


C:\\Users\\user\\Anaconda3\\Lib\\site-packages\\statsmodels\\compat\\pandas
^
SyntaxError: unexpected character after line continuation character

In [43]: from statsmodels.graphics.tsaplots import plot_acf, plot_pacf

http://localhost:8888/nbconvert/html/Untitled1.ipynb?download=false 14/15
10/2/2018 Untitled1

In [44]: plot_acf(series,alpha =.05, lags=31)

---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-44-3fff420e0e3a> in <module>()
----> 1 plot_acf(series,alpha =.05, lags=31)

~\Anaconda3\lib\site-packages\statsmodels\graphics\tsaplots.py in plot_acf(x, ax, lags, alpha, use_vlines, unbiased, fft, title, zero, vlines_kwargs, **kwargs)
132 else:
133 acf_x, confint = acf(x, nlags=nlags, alpha=alpha, fft=fft,
--> 134 unbiased=unbiased)
135
136 _plot_corr(ax, title, acf_x, confint, lags, irregular, use_vlines,

~\Anaconda3\lib\site-packages\statsmodels\tsa\stattools.py in acf(x, unbiased, nlags, qstat, fft, alpha, missing)


481 varacf[0] = 0
482 varacf[1] = 1. / nobs
--> 483 varacf[2:] *= 1 + 2 * np.cumsum(acf[1:-1]**2)
484 interval = stats.norm.ppf(1 - alpha / 2.) * np.sqrt(varacf)
485 confint = np.array(lzip(acf - interval, acf + interval))

ValueError: operands could not be broadcast together with shapes (30,) (29,) (30,)

In [45]: plot_acf(series,alpha =.05, lags=True)

Out[45]:

http://localhost:8888/nbconvert/html/Untitled1.ipynb?download=false 15/15

You might also like