728x90
In [59]:
import pandas as pd
import datetime as dt
In [60]:
avo_df = pd.read_csv('Avocado.csv')
avo_df
Out[60]:
Date | AveragePrice | Total Volume | type | region | |
---|---|---|---|---|---|
0 | 2015-12-27 | 1.33 | 64236.62 | conventional | Albany |
1 | 2015-12-20 | 1.35 | 54876.98 | conventional | Albany |
2 | 2015-12-13 | 0.93 | 118220.22 | conventional | Albany |
3 | 2015-12-06 | 1.08 | 78992.15 | conventional | Albany |
4 | 2015-11-29 | 1.28 | 51039.60 | conventional | Albany |
... | ... | ... | ... | ... | ... |
18244 | 2018-02-04 | 1.63 | 17074.83 | organic | WestTexNewMexico |
18245 | 2018-01-28 | 1.71 | 13888.04 | organic | WestTexNewMexico |
18246 | 2018-01-21 | 1.87 | 13766.76 | organic | WestTexNewMexico |
18247 | 2018-01-14 | 1.93 | 16205.22 | organic | WestTexNewMexico |
18248 | 2018-01-07 | 1.62 | 17489.58 | organic | WestTexNewMexico |
18249 rows × 5 columns
In [61]:
avo_df['Date'] = pd.to_datetime(avo_df['Date'])
avo_df
Out[61]:
Date | AveragePrice | Total Volume | type | region | |
---|---|---|---|---|---|
0 | 2015-12-27 | 1.33 | 64236.62 | conventional | Albany |
1 | 2015-12-20 | 1.35 | 54876.98 | conventional | Albany |
2 | 2015-12-13 | 0.93 | 118220.22 | conventional | Albany |
3 | 2015-12-06 | 1.08 | 78992.15 | conventional | Albany |
4 | 2015-11-29 | 1.28 | 51039.60 | conventional | Albany |
... | ... | ... | ... | ... | ... |
18244 | 2018-02-04 | 1.63 | 17074.83 | organic | WestTexNewMexico |
18245 | 2018-01-28 | 1.71 | 13888.04 | organic | WestTexNewMexico |
18246 | 2018-01-21 | 1.87 | 13766.76 | organic | WestTexNewMexico |
18247 | 2018-01-14 | 1.93 | 16205.22 | organic | WestTexNewMexico |
18248 | 2018-01-07 | 1.62 | 17489.58 | organic | WestTexNewMexico |
18249 rows × 5 columns
In [62]:
avo_df.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 18249 entries, 0 to 18248
Data columns (total 5 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 Date 18249 non-null datetime64[ns]
1 AveragePrice 18249 non-null float64
2 Total Volume 18249 non-null float64
3 type 18249 non-null object
4 region 18249 non-null object
dtypes: datetime64[ns](1), float64(2), object(2)
memory usage: 713.0+ KB
In [63]:
avo_df.set_index(keys=['Date'], inplace = True)
avo_df
Out[63]:
AveragePrice | Total Volume | type | region | |
---|---|---|---|---|
Date | ||||
2015-12-27 | 1.33 | 64236.62 | conventional | Albany |
2015-12-20 | 1.35 | 54876.98 | conventional | Albany |
2015-12-13 | 0.93 | 118220.22 | conventional | Albany |
2015-12-06 | 1.08 | 78992.15 | conventional | Albany |
2015-11-29 | 1.28 | 51039.60 | conventional | Albany |
... | ... | ... | ... | ... |
2018-02-04 | 1.63 | 17074.83 | organic | WestTexNewMexico |
2018-01-28 | 1.71 | 13888.04 | organic | WestTexNewMexico |
2018-01-21 | 1.87 | 13766.76 | organic | WestTexNewMexico |
2018-01-14 | 1.93 | 16205.22 | organic | WestTexNewMexico |
2018-01-07 | 1.62 | 17489.58 | organic | WestTexNewMexico |
18249 rows × 4 columns
In [64]:
avo_df.values
Out[64]:
array([[1.33, 64236.62, 'conventional', 'Albany'],
[1.35, 54876.98, 'conventional', 'Albany'],
[0.93, 118220.22, 'conventional', 'Albany'],
...,
[1.87, 13766.76, 'organic', 'WestTexNewMexico'],
[1.93, 16205.22, 'organic', 'WestTexNewMexico'],
[1.62, 17489.58, 'organic', 'WestTexNewMexico']], dtype=object)
In [65]:
avo_df.columns
Out[65]:
Index(['AveragePrice', 'Total Volume', 'type', 'region'], dtype='object')
In [66]:
avo_df.index
Out[66]:
DatetimeIndex(['2015-12-27', '2015-12-20', '2015-12-13', '2015-12-06',
'2015-11-29', '2015-11-22', '2015-11-15', '2015-11-08',
'2015-11-01', '2015-10-25',
...
'2018-03-11', '2018-03-04', '2018-02-25', '2018-02-18',
'2018-02-11', '2018-02-04', '2018-01-28', '2018-01-21',
'2018-01-14', '2018-01-07'],
dtype='datetime64[ns]', name='Date', length=18249, freq=None)
728x90
'Data Analytics with python > [Data Analysis]' 카테고리의 다른 글
[datetime]S7_05_Practical_example3 (0) | 2023.01.21 |
---|---|
[datetime]S7_04_Practical_example2 (0) | 2023.01.21 |
[datetime]S7_02_Timestamp (0) | 2023.01.21 |
[datetime]S7_01_datetime (0) | 2023.01.21 |
[seaborn]S6_02_pairplot,displot,heatmap(correlations) (0) | 2023.01.21 |
댓글