■ histogram 함수를 사용해 히스토그램 데이터를 구하는 방법을 보여준다.
▶ main.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
import pandas as pd import numpy as np def loadData(url, rowCount): dataFrame = pd.read_csv(url, nrows = rowCount) changeToLowerCaseString = lambda x: str(x).lower() dataFrame.rename(changeToLowerCaseString, axis = "columns", inplace = True) dataFrame["date/time"] = pd.to_datetime(dataFrame["date/time"]) return dataFrame dataFrame = loadData("https://s3-us-west-2.amazonaws.com/streamlit-demo-data/uber-raw-data-sep14.csv.gz", 10000) dataTimeSeries = dataFrame["date/time"].dt.hour historamArrayTuple = np.histogram(dataTimeSeries, bins = 24, range = (0, 24)) """ ( array([217, 122, 81, 82, 99, 161, 280, 353, 430, 396, 411, 456, 501, 526, 544, 600, 662, 747, 714, 649, 579, 567, 479, 344 ]), array([ 0., 1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12., 13., 14., 15., 16., 17., 18., 19., 20., 21., 22., 23., 24.]) ) """ histogramValueNDArray = historamArrayTuple[0] print(histogramValueNDArray) """ [217 122 81 82 99 161 280 353 430 396 411 456 501 526 544 600 662 747 714 649 579 567 479 344] """ |
▶ requirements.txt
1 2 3 4 5 6 7 8 |
numpy==2.0.0 pandas==2.2.2 python-dateutil==2.9.0.post0 pytz==2024.1 six==1.16.0 tzdata==2024.1 |
※ pip install pandas 명령을 실행했다.