Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: Pandas group by aggregate sum returning nan for a big dataset with mostly float64 values and a very few null values #60074

Closed
2 of 3 tasks
ssdv1 opened this issue Oct 19, 2024 · 0 comments
Labels
Bug Needs Triage Issue that has not been reviewed by a pandas team member

Comments

@ssdv1
Copy link

ssdv1 commented Oct 19, 2024

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

Code:
neighborhood_stats = taxi_with_neighborhood.groupby('ntaname',dropna=True).agg({
    'cost_per_mile': ['sum','count']
}).reset_index()

Output:
ntaname	cost_per_mile
sum	count
0	Airport	NaN	470286
1	Allerton-Pelham Gardens	NaN	30
2	Arden Heights	NaN	3
3	Astoria	NaN	28449
4	Auburndale	NaN	40

Issue Description

Screenshot 2024-10-19 021337
Screenshot 2024-10-19 021405
`from azureml.opendatasets import NycTlcYellow
from datetime import datetime
from dateutil import parser
import geopandas as gpd
from shapely.geometry import Point
import pandas as pd

start_date = parser.parse('2015-01-01')
end_date = parser.parse('2015-01-31')

nyc_tlc = NycTlcYellow(start_date=start_date, end_date=end_date)
taxi_data = nyc_tlc.to_pandas_dataframe()

taxi_data.info()

neighborhoods = gpd.read_file('nyc/geo_export_efe01be6-5681-4d19-b441-eefd6f6bb3fa.shp')

geometry = [Point(xy) for xy in zip(taxi_data['startLon'], taxi_data['startLat'])]
taxi_gdf = gpd.GeoDataFrame(taxi_data, geometry=geometry, crs="EPSG:4326")

taxi_with_neighborhood = gpd.sjoin(taxi_gdf, neighborhoods, how="left", predicate="within")

taxi_with_neighborhood['cost_per_mile'] = taxi_with_neighborhood['totalAmount'] / taxi_with_neighborhood['tripDistance']

taxi_with_neighborhood.reset_index(drop=True, inplace=True)

neighborhood_stats = taxi_with_neighborhood.groupby('ntaname', dropna=True).agg({
'cost_per_mile': ['sum', 'count']
}).reset_index()

neighborhood_stats.head()

taxi_with_neighborhood['cost_per_mile'][0]

cost_per_mile_sum = taxi_with_neighborhood.groupby('ntaname')['cost_per_mile'].sum()

print(cost_per_mile_sum)

taxi_with_neighborhood_pdf = pd.DataFrame(taxi_with_neighborhood)

neighborhood_stats = taxi_with_neighborhood.groupby('ntaname', dropna=True).agg({
'cost_per_mile': ['sum', 'count']
}).reset_index()

neighborhood_stats.head()

pd.show_versions()
`

Expected Behavior

should return float values for sum

Installed Versions

INSTALLED VERSIONS

commit : 0f43794
python : 3.10.15.final.0
python-bits : 64
OS : Linux
OS-release : 5.10.0-32-cloud-amd64
Version : #1 SMP Debian 5.10.223-1 (2024-08-10)
machine : x86_64
processor :
byteorder : little
LC_ALL : None
LANG : C.UTF-8
LOCALE : en_US.UTF-8

pandas : 2.0.3
numpy : 1.24.4
pytz : 2024.2
dateutil : 2.9.0
setuptools : 74.1.2
pip : 24.2
Cython : 3.0.11
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.4
IPython : 8.21.0
pandas_datareader: None
bs4 : 4.12.3
bottleneck : None
brotli : 1.1.0
fastparquet : None
fsspec : 2024.9.0
gcsfs : 2024.9.0post1
matplotlib : 3.7.3
numba : 0.58.1
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : 9.0.0
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.11.4
snappy : None
sqlalchemy : 2.0.35
tables : None
tabulate : 0.9.0
xarray : None
xlrd : None
zstandard : 0.23.0
tzdata : 2024.1
qtpy : None
pyqt5 : None

@ssdv1 ssdv1 added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Oct 19, 2024
@ssdv1 ssdv1 closed this as completed Oct 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Needs Triage Issue that has not been reviewed by a pandas team member
Projects
None yet
Development

No branches or pull requests

1 participant