id
stringlengths
7
11
source
stringclasses
1 value
category
stringclasses
11 values
title
stringlengths
15
214
text
stringlengths
70
30.5k
url
stringlengths
57
160
tags
stringlengths
3
113
created_at
int64
1.22B
1.79B
se_33483885
stackoverflow
DATA_SCIENCE
How to unstack a Pandas dataframe with two sets of variables
How to unstack a Pandas dataframe with two sets of variables I have a table that looks like this. Read from a CSV file, so no levels, no fancy indices, etc. ID date1 amount1 date2 amount2 x 15/1/2015 100 15/1/2016 80 The actual file I have goes up to date5 and amount 5. How can I convert ...
https://stackoverflow.com/questions/33483885/how-to-unstack-a-pandas-dataframe-with-two-sets-of-variables
python, pandas
1,446,486,934
se_73324491
stackoverflow
DATA_SCIENCE
How to resolve "ValueError: cannot reindex on an axis with duplicate labels" error while processing time series data in pandas?
How to resolve "ValueError: cannot reindex on an axis with duplicate labels" error while processing time series data in pandas? cube timestamp temp timestamp 2022-08-01 00:15:05.135 A1 2022-08-01 00:15:05.135 NaN 2022-08-01 00:15:37.255 A1 2022-08-01 00:15:37.25...
https://stackoverflow.com/questions/73324491/how-to-resolve-valueerror-cannot-reindex-on-an-axis-with-duplicate-labels-err
python, pandas, time-series, valueerror
1,660,237,517
se_19322506
stackoverflow
DATA_SCIENCE
Pandas DataFrames with NaNs equality comparison
Pandas DataFrames with NaNs equality comparison In the context of unit testing some functions, I'm trying to establish the equality of 2 DataFrames using python pandas: ipdb> expect 1 2 2012-01-01 00:00:00+00:00 NaN 3 2013-05-14 12:00:00+00:00 3 NaN ipdb> df identifier ...
https://stackoverflow.com/questions/19322506/pandas-dataframes-with-nans-equality-comparison
python, pandas, equality, nan
1,381,507,387
se_22649693
stackoverflow
DATA_SCIENCE
Drop rows with all zeros in pandas data frame
Drop rows with all zeros in pandas data frame I can use pandas dropna() functionality to remove rows with some or all columns set as NA's. Is there an equivalent function for dropping rows with all columns having value 0? P kt b tt mky depth 1 0 0 0 0 0 2 0 0 0 0 0 3 0 0 0 0 0 4 0...
https://stackoverflow.com/questions/22649693/drop-rows-with-all-zeros-in-pandas-data-frame
python, pandas, dataframe
1,395,796,810
se_59569963
stackoverflow
DATA_SCIENCE
Pandas monthly rolling window
Pandas monthly rolling window I am looking to do a 'monthly' rolling window on daily data grouped by a category. The code below does not work as is, it leads to the following error: ValueError: <DateOffset: months=1> is a non-fixed frequency I know that I could use '30D' offset, however this would shift the date ov...
https://stackoverflow.com/questions/59569963/pandas-monthly-rolling-window
python, pandas, dataframe, group-by, rolling-computation
1,577,998,915
se_79857809
stackoverflow
DATA_SCIENCE
Python packages installation - pandas &amp; nympy
Python packages installation - pandas &amp; nympy I have read close to all posts about this topic now but I can get it working, so sorry if you find this similar to other questions, but I can't just solve it based on existing posts. I find it very hard to install Python with its packages, and remember struggling on my...
https://stackoverflow.com/questions/79857809/python-packages-installation-pandas-nympy
python, pandas, macos, numpy, pycharm
1,767,128,978
se_62103547
stackoverflow
DATA_SCIENCE
How to convert timedelta to hours
How to convert timedelta to hours I have a timedelta Dataframe JC time 1 3days 21:02:05 2 1days 23:50:07 3 6days 19:28:36 but i want 1 93:02:05 2 47:50:07 3 163:28:36 How can I convert it?
https://stackoverflow.com/questions/62103547/how-to-convert-timedelta-to-hours
python, pandas, dataframe, timedelta
1,590,847,425
se_79857225
stackoverflow
DATA_SCIENCE
Pandas segfaults when attempting to read a multi-line cell
Pandas segfaults when attempting to read a multi-line cell I have a set of TSV files that are filled by serializing pandas dataframes built on the responses I get from querying a large database using GraphQL. In the response I get, I have a field that hosts lists, even if in the majority of cases they host a single it...
https://stackoverflow.com/questions/79857225/pandas-segfaults-when-attempting-to-read-a-multi-line-cell
python, pandas, segmentation-fault, read-csv
1,767,063,908
se_43056263
stackoverflow
DATA_SCIENCE
How to read csv without header in pandas
How to read csv without header in pandas I use Adj = pd.read_csv('xxxxxx.csv', usecols=["Adj Close"]) to read my csv file and result is looks like: Adj Close 0 0.007427 1 0.002013 2 0.008874 my csv file look like: Date Open High Low Close Volume Adj Close x x x ...
https://stackoverflow.com/questions/43056263/how-to-read-csv-without-header-in-pandas
python, pandas, dataframe, csv
1,490,647,838
se_31147477
stackoverflow
DATA_SCIENCE
Renaming columns when querying with SQLAlchemy into Pandas DataFrame
Renaming columns when querying with SQLAlchemy into Pandas DataFrame Is there a way to retain the SqlAlchemy attribute names when you query the data into a pandas dataframe? Here's a simple mapping of my database. For the school table, I've renamed 'SchoolDistrict', the DB name, to a shorter 'district'. I'm several...
https://stackoverflow.com/questions/31147477/renaming-columns-when-querying-with-sqlalchemy-into-pandas-dataframe
python, pandas, sqlalchemy
1,435,694,616
se_79653054
stackoverflow
DATA_SCIENCE
Pandas multi-column multi-assignment merge / update
Pandas multi-column multi-assignment merge / update I want to update the base pandas DataFrame with data from the update DataFrame. This applies to multiple rows of the base DataFrame (ie the merge features are not unique so can't be used as an index) and I cannot use the index matching techniques of pd.join() or pd.m...
https://stackoverflow.com/questions/79653054/pandas-multi-column-multi-assignment-merge-update
python, pandas, dataframe, join
1,749,049,902
se_59906252
stackoverflow
DATA_SCIENCE
How do I split data out from one column of a pandas dataframe into multiple columns of a new dataframe
How do I split data out from one column of a pandas dataframe into multiple columns of a new dataframe I would like to split data from this pandas dataframe (let's call it df1): YEAR CODE DIFF 2013 XXXX 5.50 2013 YYYY 8.50 2013 ZZZZ 6.50 2014 XXXX 4.50 2014 YYYY 2.50 2014 ZZZZ 3.50 Such ...
https://stackoverflow.com/questions/59906252/how-do-i-split-data-out-from-one-column-of-a-pandas-dataframe-into-multiple-colu
python, python-3.x, pandas
1,579,925,513
se_79852467
stackoverflow
DATA_SCIENCE
faster methods to remove substrings stored in one column from strings stored in another column
faster methods to remove substrings stored in one column from strings stored in another column hist_df_2["time"] = hist_df_2.apply(lambda row : hist_df_2['timestamp'].replace(str(hist_df_2['date']), ''), axis=1) I tried this to remove the date part from the timestamp. However, for some reason it took 2 minutes to exe...
https://stackoverflow.com/questions/79852467/faster-methods-to-remove-substrings-stored-in-one-column-from-strings-stored-in
python, pandas, string, dataframe
1,766,350,905
se_66047311
stackoverflow
DATA_SCIENCE
Slow numpy and pandas imports on Google Cloud Run
Slow numpy and pandas imports on Google Cloud Run I'm developping an API and deploying it on Google Cloud Run. There is a prestart python script that import pandas and numpy. When I time the imports numpy take about 2 seconds and pandas about 4 seconds on Cloud Run as opposed to less than 0.5 second on my local machin...
https://stackoverflow.com/questions/66047311/slow-numpy-and-pandas-imports-on-google-cloud-run
python, pandas, docker, google-cloud-platform, alpine-linux
1,612,447,704
se_79678365
stackoverflow
DATA_SCIENCE
Polars is less memory efficient than Pandas
Polars is less memory efficient than Pandas I want to generate a preview of spreadsheet files that users upload, in a memory-efficient manner. I'm testing using pytest-memray: import pytest import pandas as pd import polars as pl @pytest.fixture def path() -> str: return "files/rows.csv" @pytest.fixture def pa...
https://stackoverflow.com/questions/79678365/polars-is-less-memory-efficient-than-pandas
python, pandas, csv, xlsx, python-polars
1,750,813,026
se_77689378
stackoverflow
DATA_SCIENCE
how to calculate mean value of each column within range of quantile?
how to calculate mean value of each column within range of quantile? I'd like to calculate mean value of each column but only consider values are within range of quantile, like 20%-80% only. Here is why I have done, but not complete df=pd.DataFrame({"A":[1,1,20,2,2,3,50,7,8,15,20,35,50,70],"B":[10,100,20,20,200,30,50,...
https://stackoverflow.com/questions/77689378/how-to-calculate-mean-value-of-each-column-within-range-of-quantile
python, pandas, dataframe
1,703,049,975
se_79752604
stackoverflow
DATA_SCIENCE
Pandas continous time periods
Pandas continous time periods Given a table: id cost from to 43 4 2025-09-01 01:00:00 2025-09-01 01:30:00 42 4 2025-09-01 01:30:00 2025-09-01 02:00:00 41 4.8 2025-09-01 02:00:00 2025-09-01 02:30:00 40 4.05 2025-09-01 02:30:00 2025-09-01 03:00:00 39 4 2025-09-01 03:00:00 2025-09-01 03:30:00 37 5.16 202...
https://stackoverflow.com/questions/79752604/pandas-continous-time-periods
python, pandas, dataframe
1,756,734,282
se_24195432
stackoverflow
DATA_SCIENCE
Fixed effect in Pandas or Statsmodels
Fixed effect in Pandas or Statsmodels Is there an existing function to estimate fixed effect (one-way or two-way) from Pandas or Statsmodels. There used to be a function in Statsmodels but it seems discontinued. And in Pandas, there is something called plm, but I can't import it or run it using pd.plm().
https://stackoverflow.com/questions/24195432/fixed-effect-in-pandas-or-statsmodels
python, pandas, regression, statsmodels
1,402,615,418
se_79088735
stackoverflow
DATA_SCIENCE
I would like to know how to avoid unnecessary duplication when comparing two data in Pandas merge
I would like to know how to avoid unnecessary duplication when comparing two data in Pandas merge import pandas df1 = pandas.DataFrame( { 'code': ['001', '001'], 'name': ['test1', 'test1'], 'date': ['2024-01-01', '2024-01-01'], 'value1': [1, 2], 'value2': [1, 2], 'su...
https://stackoverflow.com/questions/79088735/i-would-like-to-know-how-to-avoid-unnecessary-duplication-when-comparing-two-dat
python, pandas, dataframe, merge
1,728,975,372
se_79848158
stackoverflow
DATA_SCIENCE
How to query columns that are lists or dicts?
How to query columns that are lists or dicts? How can I query columns that are lists or dicts? Here is some basic JSON-like data. [ { "id": 1, "name": "John Doe", "age": 30, "email": "john.doe@example.com", "isStudent": false, "hobbies": ["reading", "gaming", "hiking"], "a...
https://stackoverflow.com/questions/79848158/how-to-query-columns-that-are-lists-or-dicts
python, pandas, dataframe
1,765,855,262
se_69911645
stackoverflow
DATA_SCIENCE
Match Data in Excel using python
Match Data in Excel using python I am making a betting software that scrapes the fixtures from a website, puts them into an Excel file and then compares it with another Excel file that I have already manually created to find the winner (the source) The source file would look like this and The scraped output would look...
https://stackoverflow.com/questions/69911645/match-data-in-excel-using-python
python, excel, pandas, dataframe
1,636,540,112
se_79852974
stackoverflow
DATA_SCIENCE
Nuitka &amp; PyQt6 specifying imports to reducing exe size (currently ~1gb)
Nuitka &amp; PyQt6 specifying imports to reducing exe size (currently ~1gb) I'm working on a project to develop a simple app, based on a Python script for data analysis, using PyQt6 to format the app, and using Nuitka to create an exe. (Yes, I've tried using PyInstaller. My company's antivirus keeps blocking it.) The ...
https://stackoverflow.com/questions/79852974/nuitka-pyqt6-specifying-imports-to-reducing-exe-size-currently-1gb
python, pandas, scipy, pyqt6, nuitka
1,766,414,258
se_79845055
stackoverflow
DATA_SCIENCE
pd.Timestamp has attribute .isoformat, but the series accessor .dt does not
pd.Timestamp has attribute .isoformat, but the series accessor .dt does not I am trying to convert a column of pd.Timestamp objects into a columns of type str where the dates are encoded in ISO format. The class pd.Timestamp has the handy classmethod .isoformat() that does exactly what I want, though when applied to a...
https://stackoverflow.com/questions/79845055/pd-timestamp-has-attribute-isoformat-but-the-series-accessor-dt-does-not
python, pandas, timestamp, iso8601
1,765,556,626
se_79837366
stackoverflow
DATA_SCIENCE
get the DB insert statement to preserve column casing by quoting the column names
get the DB insert statement to preserve column casing by quoting the column names I'm trying to read a CSV file and write to an Oracle database table. CSV file: "id_field","last_updated_date" "123456",2021-08-07 16:26:45.299 DDL creating the Oracle schema and table: CREATE USER "my_schema" IDENTIFIED BY "Password123"...
https://stackoverflow.com/questions/79837366/get-the-db-insert-statement-to-preserve-column-casing-by-quoting-the-column-name
python, pandas, oracle-database, sqlalchemy
1,764,799,913
se_76402530
stackoverflow
DATA_SCIENCE
TypeError: concat() takes 1 positional argument but 2 were given
TypeError: concat() takes 1 positional argument but 2 were given I want to concatenate the pandas dataframes in a column-wise manner and reset the index. import pandas as pd import numpy as np com_mut = kirc_mut.loc[common_samples] com_mut = com_mut.sort_index() com_mut = com_mut.T com_mut = com_mut.dropna() com_mut ...
https://stackoverflow.com/questions/76402530/typeerror-concat-takes-1-positional-argument-but-2-were-given
python, pandas
1,685,915,186
se_79757853
stackoverflow
DATA_SCIENCE
Manipulating a large dataframe most efficiently
Manipulating a large dataframe most efficiently Imagine I have this dataframe called temp: temp = pd.DataFrame(index = [x for x in range(0, 10)], columns = list('abcd')) for row in temp.index: temp.loc[row] = default_rng().choice(10, size=4, replace=False) temp.loc[1, 'b'] = np.nan temp.loc[3, 'd'] = np.nan ...
https://stackoverflow.com/questions/79757853/manipulating-a-large-dataframe-most-efficiently
python, pandas, dataframe, numpy, pytorch
1,757,202,088
se_75526866
stackoverflow
DATA_SCIENCE
GeoPandas spatial join - no matching rows in the resultant dataset
GeoPandas spatial join - no matching rows in the resultant dataset I have two GeoPandas DataFrames that I am attempting to join. I set the crs for both and then use sjoin and sjoin_nearest, however, I am not seeing any results. The columns are NaNs. import pandas as pd import geopandas as gpd df1 = pd.DataFrame({ ...
https://stackoverflow.com/questions/75526866/geopandas-spatial-join-no-matching-rows-in-the-resultant-dataset
python, pandas, geospatial, geopandas
1,677,021,801
se_56302411
stackoverflow
DATA_SCIENCE
how to check whether column of text contains specific string or not in pandas
how to check whether column of text contains specific string or not in pandas I have following dataframe in pandas job_desig salary senior analyst 12 junior researcher 5 scientist 20 sr analyst 12 Now I want to generate one column which will have a flag set as bel...
https://stackoverflow.com/questions/56302411/how-to-check-whether-column-of-text-contains-specific-string-or-not-in-pandas
python, pandas
1,558,766,391
se_54924866
stackoverflow
DATA_SCIENCE
How does distribution works in dask?
How does distribution works in dask? I have a dataframe: import numpy as np import pandas as pd import dask.dataframe as dd a = {'b':['cat','bat','cat','cat','bat','No Data','bat','No Data'], 'c':['str1','str2','str3', 'str4','str5','str6','str7', 'str8'] } df11 = pd.DataFrame(a,index=['x1','x2','x3','x4','x5...
https://stackoverflow.com/questions/54924866/how-does-distribution-works-in-dask
python, pandas, numpy, dask, dask-distributed
1,551,353,947
se_79747317
stackoverflow
DATA_SCIENCE
How to sort pandas groups by (multiple/all) values of the groups?
How to sort pandas groups by (multiple/all) values of the groups? I am trying to do a somewhat complicated group and sort operation in pandas. I want to sort the groups by their values in ascending order, using successive values for tiebreaks as needed. I have read the similar question Pandas dataframe: How to sort gr...
https://stackoverflow.com/questions/79747317/how-to-sort-pandas-groups-by-multiple-all-values-of-the-groups
python, pandas, dataframe, sorting, group-by
1,756,241,679
se_49799731
stackoverflow
DATA_SCIENCE
How to get the first group in a groupby of multiple columns?
How to get the first group in a groupby of multiple columns? I've been trying to figure out how I can return just the first group, after I apply groupby. My code looks like this: gb = df.groupby(['col1', 'col2', 'col3', 'col4'])['col5'].sum() What I want is for that first first group to output. I've been trying ...
https://stackoverflow.com/questions/49799731/how-to-get-the-first-group-in-a-groupby-of-multiple-columns
python, pandas, dataframe, group-by
1,523,544,816
se_63581625
stackoverflow
DATA_SCIENCE
How to get the base file name from a column of paths
How to get the base file name from a column of paths I have a DataFrame with the column of file paths. I want to change it to only the file name. My DataFrame looks like: df = pd.DataFrame({ 'Sr No': [18, 19, 20], 'Email': ['Test@test.com', 'Test@test.com', 'Test@test.com'], 'filename': [r'C:/Users\Test.cs...
https://stackoverflow.com/questions/63581625/how-to-get-the-base-file-name-from-a-column-of-paths
python, pandas, path, filenames
1,598,367,361
se_19611729
stackoverflow
DATA_SCIENCE
Getting Google Spreadsheet CSV into A Pandas Dataframe
Getting Google Spreadsheet CSV into A Pandas Dataframe I uploaded a file to Google spreadsheets (to make a publically accessible example IPython Notebook, with data) I was using the file in it's native form could be read into a Pandas Dataframe. So now I use the following code to read the spreadsheet, works fine but j...
https://stackoverflow.com/questions/19611729/getting-google-spreadsheet-csv-into-a-pandas-dataframe
python, pandas, google-sheets, google-drive-api, google-apps
1,382,820,411
se_48835158
stackoverflow
DATA_SCIENCE
Add column to dataframe from .apply
Add column to dataframe from .apply I have a small issue manipulating a dataframe to create a new variable function of others. I am able to calculate it, but not to aggregate it back to the original dataframe. Here I have my test dataframe and my new_column test = pd.DataFrame({'name': ["john", "jack", "albert"], ...
https://stackoverflow.com/questions/48835158/add-column-to-dataframe-from-apply
python, pandas
1,518,816,724
se_79844080
stackoverflow
DATA_SCIENCE
How to duplicate columns with a prefix/suffix when flattening a DataFrameGroupBy
How to duplicate columns with a prefix/suffix when flattening a DataFrameGroupBy I've been working on a project to learn Python and play around with machine learning that uses data from the NHL's public API. I've been able to teach myself via documentation and Google searches so far, but I've gotten stumped on my cur...
https://stackoverflow.com/questions/79844080/how-to-duplicate-columns-with-a-prefix-suffix-when-flattening-a-dataframegroupby
python, pandas, dataframe, group-by, merge
1,765,465,354
se_79846641
stackoverflow
DATA_SCIENCE
How to print the value counts of a user-selected column in a pandas DataFrame?
How to print the value counts of a user-selected column in a pandas DataFrame? I’m trying to write a Python script that allows the user to input the name of a column and then prints the value counts of that column from a pandas DataFrame. Here's what I currently have: def count_unique_values(df, column_list): for ...
https://stackoverflow.com/questions/79846641/how-to-print-the-value-counts-of-a-user-selected-column-in-a-pandas-dataframe
python, pandas, dataframe
1,765,646,807
se_79844489
stackoverflow
DATA_SCIENCE
Shifting string values to a previous column in a dataframe
Shifting string values to a previous column in a dataframe Here is what i have in a dataframe where a column has names and some numbers together since this is a table extracted from a PDF 0 1 2 3 4 Mr. A 75 #of mammo cases 5 ...
https://stackoverflow.com/questions/79844489/shifting-string-values-to-a-previous-column-in-a-dataframe
python, pandas, dataframe
1,765,502,557
se_79847020
stackoverflow
DATA_SCIENCE
Access data frame from binary file
Access data frame from binary file if I have saved a data frame using pickle in a binary file how can I access it? def create_dataset(path): """ creates an binary file with dataset saved in it. """ df = pd.read_csv(path) saved_path = "some_path" with open(saved_path,'wb+') as f: pkl...
https://stackoverflow.com/questions/79847020/access-data-frame-from-binary-file
python, pandas, dataframe
1,765,715,854
se_14035148
stackoverflow
DATA_SCIENCE
Import netCDF file to Pandas dataframe
Import netCDF file to Pandas dataframe I am trying to read in a netCDF file, which I can do and then import that into a pandas dataframe. The netCDF file is 2D so I just want to 'dump it in'. I have tried the DataFrame method but it doesn't recognize the object. Presumably I need to convert the netCDF object to a 2D n...
https://stackoverflow.com/questions/14035148/import-netcdf-file-to-pandas-dataframe
python, dataframe, pandas, netcdf
1,356,484,826
se_79830100
stackoverflow
DATA_SCIENCE
Best way to clean awkward Excel column headers in python/pandas?
Best way to clean awkward Excel column headers in python/pandas? I've got four years of daily school attendance data spread across 40+ Excel files (one for each month) and the sheets are set up in a truly annoying fashion, with each date in one merged cell in the first row while the total enrolment and daily absences ...
https://stackoverflow.com/questions/79830100/best-way-to-clean-awkward-excel-column-headers-in-python-pandas
python, excel, pandas, data-cleaning
1,764,097,658
se_77290951
stackoverflow
DATA_SCIENCE
Merge DataFrame float column with DataFrame pandas Interval column
Merge DataFrame float column with DataFrame pandas Interval column I have 2 DataFrames that I want to merge. import pandas as pd df1=pd.DataFrame.from_dict({ 'names':['klas','erik','stefan'], 'age':[6,17.5,28] }) df2=pd.DataFrame.from_dict( {'salary':[10,15,45,600], 'names':['klas','erik','stefan','stefan'], 'age...
https://stackoverflow.com/questions/77290951/merge-dataframe-float-column-with-dataframe-pandas-interval-column
pandas, dataframe, merge, intervals
1,697,236,095
se_79846597
stackoverflow
DATA_SCIENCE
When big data : requests.exceptions.ConnectionError: (&#39;Connection aborted.&#39;, RemoteDisconnected(&#39;Remote end closed connection without response&#39;))
When big data : requests.exceptions.ConnectionError: (&#39;Connection aborted.&#39;, RemoteDisconnected(&#39;Remote end closed connection without response&#39;)) The problem appears when i have a big amount of values in my pandas df. When i take 27 or 54 values(1 or 2 columns) it works normaly, but when i take more co...
https://stackoverflow.com/questions/79846597/when-big-data-requests-exceptions-connectionerror-connection-aborted-rem
python, pandas, google-sheets-api, gspread
1,765,639,139
se_79844967
stackoverflow
DATA_SCIENCE
Bizzare &quot;kernel has died&quot; error in pandas df.to_excel() caused by geopandas
Bizzare &quot;kernel has died&quot; error in pandas df.to_excel() caused by geopandas When pandas.read_excel(), df.to_excel(), geopandas.read_file() and gdf.to_file() are called in a certain order in different environments, pd.read_excel() sometimes causes "Kernel has died" errors. I already tried reading and writing ...
https://stackoverflow.com/questions/79844967/bizzare-kernel-has-died-error-in-pandas-df-to-excel-caused-by-geopandas
python, excel, pandas, dataframe, geopandas
1,765,549,929
se_71433983
stackoverflow
DATA_SCIENCE
Unable to allocate 11.6 GiB for an array with shape (1554122468,) and data type int64
Unable to allocate 11.6 GiB for an array with shape (1554122468,) and data type int64 I am getting kind of weird error when I tried to Merged my Dataframe files which has 930333 rows & 21 columns in FullRaw1 as well 56078 rows & 2 columns in CustTag at the time of merge i'm getting error of "Unable to allocate 11.6 Gi...
https://stackoverflow.com/questions/71433983/unable-to-allocate-11-6-gib-for-an-array-with-shape-1554122468-and-data-type
python, pandas, dataframe, numpy, merge
1,646,976,199
se_79843343
stackoverflow
DATA_SCIENCE
Python delta time series conversion to time data type
Python delta time series conversion to time data type I have a column named ride_length that is the difference between two datetime columns. It has a data type of time delta series. How can I convert it into a time data type? Current format 1 day 12:58:20 Required format HH:MM:SS
https://stackoverflow.com/questions/79843343/python-delta-time-series-conversion-to-time-data-type
python, pandas, datetime
1,765,392,404
se_55319655
stackoverflow
DATA_SCIENCE
Pandas: How to replace Zero values in a column with the mean of that column, For all columns with Zero Value
Pandas: How to replace Zero values in a column with the mean of that column, For all columns with Zero Value I have a dataframe with multiple values as zero. I want to replace the values that are zero with the mean values of that column Without repeating code. I have columns called runtime, budget, and revenue that a...
https://stackoverflow.com/questions/55319655/pandas-how-to-replace-zero-values-in-a-column-with-the-mean-of-that-column-for
python, pandas
1,553,387,292
se_36106490
stackoverflow
DATA_SCIENCE
How to get unique values from multiple columns in a pandas groupby
How to get unique values from multiple columns in a pandas groupby Starting from this dataframe df: df = pd.DataFrame({'c':[1,1,1,2,2,2],'l1':['a','a','b','c','c','b'],'l2':['b','d','d','f','e','f']}) c l1 l2 0 1 a b 1 1 a d 2 1 b d 3 2 c f 4 2 c e 5 2 b f I would like to perform a groupby ove...
https://stackoverflow.com/questions/36106490/how-to-get-unique-values-from-multiple-columns-in-a-pandas-groupby
python, pandas
1,458,417,627
se_79758951
stackoverflow
DATA_SCIENCE
Remove items within pandas DataFrameGroupBy groups
Remove items within pandas DataFrameGroupBy groups I have a dataframe df made up of n columns which are groups and one, "data". This dataframe is then grouped on the n group columns. df = pd.DataFrame(data={"g0": ["foo", "foo", "bar", "bar"], "g1": ["baz", "baz", "baz", "qux"], ...
https://stackoverflow.com/questions/79758951/remove-items-within-pandas-dataframegroupby-groups
python, pandas, dataframe, group-by
1,757,338,417
se_79842936
stackoverflow
DATA_SCIENCE
Behavior of .groupby and .transform - length mismatch
Behavior of .groupby and .transform - length mismatch I've been experimenting with pandas for my data analysis, however I encountered an issue when dealing with .groupby() and .transform() . Let this be the dataframe: df = pd.DataFrame({ 'group': ['x','x','x','y','y','z'], 'b': [1, 2, 1, 3, 3, 4] }) gr...
https://stackoverflow.com/questions/79842936/behavior-of-groupby-and-transform-length-mismatch
python, pandas, dataframe, group-by
1,765,369,020
se_79763274
stackoverflow
DATA_SCIENCE
How to set a cell value based on the time range in DatetimeIndex in Pandas
How to set a cell value based on the time range in DatetimeIndex in Pandas I am trying to create a new column in a pandas dataframe, where the values are based on ranges of the time (hours and minute) of the DatetimeIndex. Here is my dataframe: DatetimeIndex col_1 2020-07-10 10:00:00+00:00 A 2020-07-10...
https://stackoverflow.com/questions/79763274/how-to-set-a-cell-value-based-on-the-time-range-in-datetimeindex-in-pandas
python, pandas, datetimeindex
1,757,703,703
se_33355811
stackoverflow
DATA_SCIENCE
matplotlib conditional background color in python
matplotlib conditional background color in python How can I change the background color of a line chart based on a variable that is not in the chart? For example if I have the following dataframe: import numpy as np import pandas as pd dates = pd.date_range('20000101', periods=800) df = pd.DataFrame(index=dates) df...
https://stackoverflow.com/questions/33355811/matplotlib-conditional-background-color-in-python
python, pandas, matplotlib
1,445,894,291
se_45985358
stackoverflow
DATA_SCIENCE
How to wrap text for an entire column using Pandas?
How to wrap text for an entire column using Pandas? I want to use Pandas, to wrap an entire column. I have already set the width for the columns now I just need to wrap the entire column as they are all in 1 line. I do not need to edit the width of the columns, I want to wrap the text in the cells. I can do this in Ex...
https://stackoverflow.com/questions/45985358/how-to-wrap-text-for-an-entire-column-using-pandas
python, pandas, excel
1,504,193,956
se_79040490
stackoverflow
DATA_SCIENCE
Conditions in functions in pandas
Conditions in functions in pandas I am new to Pandas and trying to figure out how to create/use functions, perform simple if-else statements. I wrote the following function average_shares(), but it doesn't work as I expect (because it should be written for rows, not columns, but I don't get it/ don't know how to fix t...
https://stackoverflow.com/questions/79040490/conditions-in-functions-in-pandas
python, pandas, numpy, control-flow
1,727,718,226
se_79843205
stackoverflow
DATA_SCIENCE
How to find corrupted date entry when date column type is (object)
How to find corrupted date entry when date column type is (object) I am trying to convert a column of time stamps that are currently of type object to proper datetime. When using pd.to_datetime() on the column I got this error OutOfBoundsDatetime: Out of bounds nanosecond timestamp: 2821-11-10, at position 1818 I ju...
https://stackoverflow.com/questions/79843205/how-to-find-corrupted-date-entry-when-date-column-type-is-object
python, pandas, dataframe, datetime
1,765,384,359
se_62458837
stackoverflow
DATA_SCIENCE
Groupby transform to list in pandas does not work
Groupby transform to list in pandas does not work Best described with an example import pandas as pd df = pd.DataFrame({ 'a' : ['A','B','C','A','B','C','A','B','C'], 'b': [1,2,3,4,5,6,7,8,9]} ) And i want to create a column that contains in a list the elements of column b by group of column a resulting in ...
https://stackoverflow.com/questions/62458837/groupby-transform-to-list-in-pandas-does-not-work
python, pandas, dataframe, group-by
1,592,512,079
se_61119289
stackoverflow
DATA_SCIENCE
How to reindex a specific column in Pandas?
How to reindex a specific column in Pandas? gd = df.groupby(['subID'])['Accuracy'].std() print(gd) subID 4 0.810423 5 0.841364 6 0.881007 8 0.763175 9 0.760102 10 0.905283 12 0.928358 14 0.779291 15 0.912377 1018 0.926683 It displays like this and I assume it...
https://stackoverflow.com/questions/61119289/how-to-reindex-a-specific-column-in-pandas
python, pandas, group-by, series, reindex
1,586,428,834
se_79842390
stackoverflow
DATA_SCIENCE
Conditionnal IF use not working with PD.NOTNA
Conditionnal IF use not working with PD.NOTNA Amateur programmer here, trying to make my working life bette. I am building a billing program, using selenium webdriver, to facilitate people entering their information into the more complex web-based "official" billing system. The user imports a .csv file containing the ...
https://stackoverflow.com/questions/79842390/conditionnal-if-use-not-working-with-pd-notna
python, pandas, dataframe
1,765,316,959
se_79237626
stackoverflow
DATA_SCIENCE
Read CSV - There should be a unique row for each daily entry combining health metrics and supplement usage
Read CSV - There should be a unique row for each daily entry combining health metrics and supplement usage Can you help me with the interpretation of this sentence ? Does this mean you should group by date rows with different supplement usage? Or should I have 2 rows, one for magnesium and one for placebo? If I hav...
https://stackoverflow.com/questions/79237626/read-csv-there-should-be-a-unique-row-for-each-daily-entry-combining-health-me
python, pandas, database, read-csv
1,732,894,552
se_79320257
stackoverflow
DATA_SCIENCE
customize header pandas to html
customize header pandas to html I created a web application to search content in CSV files.for now i only able to put all content into 1 column with comma as delimiter , I want to display the data as shown in the image. My python code selected_columns = [202, 9, 10, 135, 13, 127, 126, 26, 28,128,129,31,33] df = df.ilo...
https://stackoverflow.com/questions/79320257/customize-header-pandas-to-html
python, pandas, read-csv
1,735,657,814
se_79419035
stackoverflow
DATA_SCIENCE
Pandas text file import: automate selection of 1 table when many exist within each file
Pandas text file import: automate selection of 1 table when many exist within each file Using Pandas 2.2.1 within Python 3.12, I'm importing data from text files that have a varying number of rows of metadata and multiple tables that precede the actual data to be imported. The number of rows that need to be skipped is...
https://stackoverflow.com/questions/79419035/pandas-text-file-import-automate-selection-of-1-table-when-many-exist-within-ea
python, pandas, read-csv
1,738,867,682
se_41221079
stackoverflow
DATA_SCIENCE
Rename MultiIndex columns in Pandas
Rename MultiIndex columns in Pandas df = pd.DataFrame([[1,2,3], [10,20,30], [100,200,300]]) df.columns = pd.MultiIndex.from_tuples((("a", "b"), ("a", "c"), ("d", "f"))) df returns a d b c f 0 1 2 3 1 10 20 30 2 100 200 300 and df.columns.levels[1] returns Index([u'b',...
https://stackoverflow.com/questions/41221079/rename-multiindex-columns-in-pandas
python, pandas, dataframe
1,482,145,012
se_79842077
stackoverflow
DATA_SCIENCE
Pandas &#39;sep&#39; Command Not Working for Text File
Pandas &#39;sep&#39; Command Not Working for Text File I have the following (shortened) list of data (State Vector for an arbitrary satellite): 0.0000000000000000e+00 6.0513311190355308e+06 -2.3889553726207524e-10 -3.9014601994371545e+06 4.0317846206431714e+03 3.8291459195655465e-13 6.2534698530736323e+03 6.000...
https://stackoverflow.com/questions/79842077/pandas-sep-command-not-working-for-text-file
python, pandas, dataframe, read-csv
1,765,291,812
se_69298394
stackoverflow
DATA_SCIENCE
I have a Dataframe with very long text content and I wish to save it as a table (in .PNG) but text is getting cropped out
I have a Dataframe with very long text content and I wish to save it as a table (in .PNG) but text is getting cropped out I used the following code in order to save a dataframe as a picture import dataframe_image as dfi dfi.export(df,"df.png") where df is the dataframe but ended up getting cropped text. It retains on...
https://stackoverflow.com/questions/69298394/i-have-a-dataframe-with-very-long-text-content-and-i-wish-to-save-it-as-a-table
python, pandas, dataframe
1,632,393,380
se_54953967
stackoverflow
DATA_SCIENCE
Your session crashed after using all available RAM in Google Collab
Your session crashed after using all available RAM in Google Collab I have 6 big data tsv files which I am reading into dataframes within Google Collab. However, the files are too big and Google Colab cannot handle it. #Crew data downloaded = drive.CreateFile({'id':'16'}) downloaded.GetContentFile('title.crew.tsv') ...
https://stackoverflow.com/questions/54953967/your-session-crashed-after-using-all-available-ram-in-google-collab
python, pandas, dataframe, google-colaboratory
1,551,485,516
se_74383395
stackoverflow
DATA_SCIENCE
Property &#39;sheets&#39; of &#39;OpenpyxlWriter&#39; object has no setter using pandas and openpyxl
Property &#39;sheets&#39; of &#39;OpenpyxlWriter&#39; object has no setter using pandas and openpyxl This code used to get a xlsx file and write over it, but after updating from pandas 1.1.5 to 1.5.1 I got zipfile.badzipfile file is not a zip file Then I read here that after pandas 1.2.0 the pd.ExcelWriter(report_path...
https://stackoverflow.com/questions/74383395/property-sheets-of-openpyxlwriter-object-has-no-setter-using-pandas-and-open
python, pandas, openpyxl, setter
1,668,045,937
se_79765445
stackoverflow
DATA_SCIENCE
Get rows with unique value in a specific column in pandas
Get rows with unique value in a specific column in pandas Following is my data frame. id name class -------------------------- 0 Nick a 1 Jane b 2 Jacon a 3 Jack b 4 Cooze a -------------------------- 5 Nick b 6 Jane ...
https://stackoverflow.com/questions/79765445/get-rows-with-unique-value-in-a-specific-column-in-pandas
python, pandas
1,757,957,695
se_74277254
stackoverflow
DATA_SCIENCE
How to merge multiple CSV files based on specific column IDs
How to merge multiple CSV files based on specific column IDs import pandas as pd videos_list = { 'Video ID': ['aaa', 'bbb', 'ccc'], 'Title': ['Video Title AAA', 'Video Title BBB', 'Video Title CCC'], 'Views': ['100', '30', '60']} transcripts_list = { 'Title': ['Video Title AAA', 'Vide...
https://stackoverflow.com/questions/74277254/how-to-merge-multiple-csv-files-based-on-specific-column-ids
python, pandas, dataframe, csv, merge
1,667,311,915
se_76684141
stackoverflow
DATA_SCIENCE
Why am I getting an error when using &#39;squeeze&#39; keyword in &#39;read_csv&#39;?
Why am I getting an error when using &#39;squeeze&#39; keyword in &#39;read_csv&#39;? alcohol = pd.read_csv('https://andybek.com/pandas-drinks', usecols=['country','wine_servings'], index_col='country', squeeze=True) When using the keyword squeeze to convert a one columned dataframe to series, I'm getting an error Ty...
https://stackoverflow.com/questions/76684141/why-am-i-getting-an-error-when-using-squeeze-keyword-in-read-csv
python, pandas, dataframe, csv
1,689,297,421
se_79840254
stackoverflow
DATA_SCIENCE
How can I handle missing values in a large pandas DataFrame without running out of memory?
How can I handle missing values in a large pandas DataFrame without running out of memory? I’m working with a large pandas DataFrame (~5 million rows, ~40 columns). When I try operations like: df = df.fillna(0) # or df = df.dropna() my RAM usage spikes and sometimes my Jupyter notebook crashes. I understand that pand...
https://stackoverflow.com/questions/79840254/how-can-i-handle-missing-values-in-a-large-pandas-dataframe-without-running-out
python, pandas, dataframe
1,765,114,039
se_27534402
stackoverflow
DATA_SCIENCE
Solving linearised least squares using statsmodels
Solving linearised least squares using statsmodels I'm trying to translate a simple linearised least squares problem to statsmodels, in order to learn how to use it for iterative least squares: The (contrived) data comprise measurements of the time it takes for a ball to drop a given distance. distance time 10 ...
https://stackoverflow.com/questions/27534402/solving-linearised-least-squares-using-statsmodels
python, pandas, least-squares, statsmodels
1,418,848,564
se_79839281
stackoverflow
DATA_SCIENCE
Multiindexed Pandas Series to Yes/No table
Multiindexed Pandas Series to Yes/No table I have a MultiIndex table as follows Index0 Index1 Variable A 0 "a" A 1 "x" A 2 "t" B 0 "x" B 1 "a" C 0 "a" C 1 "t" And I want the following output Index "a" "x" "t" A 1 1 1 ...
https://stackoverflow.com/questions/79839281/multiindexed-pandas-series-to-yes-no-table
python, pandas, dataframe, reshape
1,764,967,058
se_45352909
stackoverflow
DATA_SCIENCE
Pandas: IndexingError: Unalignable boolean Series provided as indexer
Pandas: IndexingError: Unalignable boolean Series provided as indexer I'm trying to run what I think is simple code to eliminate any columns with all NaNs, but can't get this to work (axis = 1 works just fine when eliminating rows): import pandas as pd import numpy as np df = pd.DataFrame({'a':[1,2,np.nan,np.nan], '...
https://stackoverflow.com/questions/45352909/pandas-indexingerror-unalignable-boolean-series-provided-as-indexer
python, pandas, dataframe
1,501,163,713
se_40353079
stackoverflow
DATA_SCIENCE
How to check dtype for all columns in a Pandas dataframe?
How to check dtype for all columns in a Pandas dataframe? It seems that dtype only works for Series, right? Is there a function to display data types of all columns at once?
https://stackoverflow.com/questions/40353079/how-to-check-dtype-for-all-columns-in-a-pandas-dataframe
python, pandas, dataframe
1,477,965,018
se_79822801
stackoverflow
DATA_SCIENCE
Efficiently get first indices of consecutive identical digits in big pandas DataFrames
Efficiently get first indices of consecutive identical digits in big pandas DataFrames I have a DataFrame with a column Digit of digits at base 10. For example import numpy as np import pandas as pd df = pd.DataFrame({ "Digit": [ 1, 3, 5, 7, 0, 0, 0, 4, 8, 9, 7, 7, 7, 7, 9, 3, 3, 1, 6, 8,...
https://stackoverflow.com/questions/79822801/efficiently-get-first-indices-of-consecutive-identical-digits-in-big-pandas-data
python, pandas, dataframe
1,763,415,111
se_58834968
stackoverflow
DATA_SCIENCE
Erase columns where duplicated rows exist, in groups. Pandas
Erase columns where duplicated rows exist, in groups. Pandas I need to show columns which have only duplicated rows inside, in Name groups I cannot remove/drop columns for one groupo because for other this specific column could be usefull. So when in specific column will be duplicates i need to make this column empty ...
https://stackoverflow.com/questions/58834968/erase-columns-where-duplicated-rows-exist-in-groups-pandas
python, pandas
1,573,640,705
se_79837737
stackoverflow
DATA_SCIENCE
How to merge pandas dataframes with MultiIndexes on the columns
How to merge pandas dataframes with MultiIndexes on the columns I am trying to merge two pandas dataframes together that have a MultiIndex on the columns. This works as expected when there are no duplicate columns, however when there are duplicate columns, it simply marks the top level of the index on the right hand d...
https://stackoverflow.com/questions/79837737/how-to-merge-pandas-dataframes-with-multiindexes-on-the-columns
python, pandas, dataframe, multi-index
1,764,839,607
se_79837276
stackoverflow
DATA_SCIENCE
Utilizing a loop or automated approach to join all possible elements in one dataframes together based on defined criteria
Utilizing a loop or automated approach to join all possible elements in one dataframes together based on defined criteria Summary: I want to be able to recreate my SQL code via Python such that I dont have to manually type out each join for situations when the combinations get too large to handle I have one table impo...
https://stackoverflow.com/questions/79837276/utilizing-a-loop-or-automated-approach-to-join-all-possible-elements-in-one-data
python, pandas, dataframe, function, pyspark
1,764,792,038
se_79837512
stackoverflow
DATA_SCIENCE
Forecasting : FB Prophet function doesn&#39;t start from last datapoint in python
Forecasting : FB Prophet function doesn&#39;t start from last datapoint in python I've noticed that Facebook's Prophet function does a good job with forecasting. However, for my data, it never starts at the last value of y-predict. As you can see in the image, the last value of Total_Issues is 168, but the function pr...
https://stackoverflow.com/questions/79837512/forecasting-fb-prophet-function-doesnt-start-from-last-datapoint-in-python
python, pandas, time-series, forecasting, facebook-prophet
1,764,823,521
se_79810856
stackoverflow
DATA_SCIENCE
Value count accuracy
Value count accuracy I was trying to calculate the accuracy of my roberta label and pre existing dataset label enter image description here enter image description here i was confused on how to operate pandas's value_counts(), i dont know how to do operations on it before, the error says it needs identical series, but...
https://stackoverflow.com/questions/79810856/value-count-accuracy
python, pandas, roberta-language-model, best-practices
1,762,404,463
se_38359919
stackoverflow
DATA_SCIENCE
pandas collapse Series values into one value
pandas collapse Series values into one value How does one collapse a Series into one value? I tried pd.concat(). dict = {"Cities": ["Chicago", "Hong Kong", "London"], "People": ["John", "Mike", "Sue"]} df = pd.Dataframe.from_dict(dict) Cities People 0 Chicago John 1 Hong Kong Mike 2 Lon...
https://stackoverflow.com/questions/38359919/pandas-collapse-series-values-into-one-value
python, pandas, concatenation, series
1,468,437,239
se_79836341
stackoverflow
DATA_SCIENCE
GreatExpectations; ExpectColumnValuesToBeIncreasing; &#39;&gt;=&#39; not supported between instances of &#39;Timedelta&#39; and &#39;int&#39;
GreatExpectations; ExpectColumnValuesToBeIncreasing; &#39;&gt;=&#39; not supported between instances of &#39;Timedelta&#39; and &#39;int&#39; I try to load many different csv files and data check them with GreatExpecatations. It works for ExpectColumnValuesToNotBeNull, ExpectColumnValuesToBeUnique and ExpectColumnValu...
https://stackoverflow.com/questions/79836341/greatexpectations-expectcolumnvaluestobeincreasing-not-supported-between
python, pandas, typeerror, great-expectations
1,764,711,483
se_79810618
stackoverflow
DATA_SCIENCE
Filter a pandas df: per group, keep only non-null rows if we have them, else keep a single null row
Filter a pandas df: per group, keep only non-null rows if we have them, else keep a single null row Hopefully the title is reasonably intuitive, edits welcome. Say I have this dataframe: df = pd.DataFrame({'x': ['A', 'B', 'B', 'C', 'C', 'C', 'D', 'D'], 'y': [None, None, 1, 2, 3, 4, None, None]}) ...
https://stackoverflow.com/questions/79810618/filter-a-pandas-df-per-group-keep-only-non-null-rows-if-we-have-them-else-kee
python, pandas, dataframe, filter, group-by
1,762,377,620
se_55471750
stackoverflow
DATA_SCIENCE
How do i remove outliers using multiple columns pandas?
How do i remove outliers using multiple columns pandas? Out of my entire dataframe i have two columns price and quantity. These both contain outliers. How can i remove the outliers in both these columns such that the dataframe returned excludes outliers from both these columns? I can apply it to one but not sure how i...
https://stackoverflow.com/questions/55471750/how-do-i-remove-outliers-using-multiple-columns-pandas
python, pandas, dataframe, outliers
1,554,198,630
se_79835498
stackoverflow
DATA_SCIENCE
How do I sort a Pandas DataFrame using a column name stored in a variable?
How do I sort a Pandas DataFrame using a column name stored in a variable? I am working with a Pandas DataFrame containing student data (GRE scores, TOEFL scores, etc.). I need to sort this DataFrame based on a specific column, but the column name is provided by the user as input (it is not hard-coded). I know how to ...
https://stackoverflow.com/questions/79835498/how-do-i-sort-a-pandas-dataframe-using-a-column-name-stored-in-a-variable
python, pandas, dataframe, sorting
1,764,651,898
se_79826932
stackoverflow
DATA_SCIENCE
How to Create a Pandas Dataframe from JSON Nested Objects
How to Create a Pandas Dataframe from JSON Nested Objects I'm trying to create a Pandas DataFrame from a JSON file that looks like this: { "GameID": "1,218,463,841", "Date - Start": "1761097369", "Date - End": "1761098306", "TagSetID": 79, "Netplay": 1, "StadiumID": 5, "Away Player": "margoose", "Home ...
https://stackoverflow.com/questions/79826932/how-to-create-a-pandas-dataframe-from-json-nested-objects
python, json, pandas, json-normalize
1,763,758,044
se_79835136
stackoverflow
DATA_SCIENCE
Convert this date/time format into pandas datetime
Convert this date/time format into pandas datetime I downloaded some data from a data repository to do some analysis, and it is in a format that I have never seen and do not know how to work with. import pandas as pd raw={ 'Fill':['text','','','text','','','text','',''], 'Time':['25-Jan-01','00:00','12:00','25...
https://stackoverflow.com/questions/79835136/convert-this-date-time-format-into-pandas-datetime
python, pandas, dataframe
1,764,610,619
se_46754398
stackoverflow
DATA_SCIENCE
Pandas Merge returns NaN
Pandas Merge returns NaN I have issues with the merging of two large Dataframes since the merge returns NaN values though there are fitting values. The two dfs are shaped like: df1 Motor 2232 1524 2230 2230 2224 1516 1724 2224 1524 1624 1724 2224 2224 1524 1524 1516 1524 2224 1624 1724 1724 2224 2224 df2 Motor ...
https://stackoverflow.com/questions/46754398/pandas-merge-returns-nan
python, pandas, dataframe, merge
1,508,065,984
se_33268053
stackoverflow
DATA_SCIENCE
Indexing a pandas dataframe with datetime.date index leads to KeyError
Indexing a pandas dataframe with datetime.date index leads to KeyError I retrieve some data from my MySQL database. This data has the date (not datetime) in one column and some other random data in the other columns. Let's say dtf is my dataframe. There is no index yet so I set one dtf.set_index('date', inplace=True) ...
https://stackoverflow.com/questions/33268053/indexing-a-pandas-dataframe-with-datetime-date-index-leads-to-keyerror
python, mysql, pandas, dataframe, date
1,445,457,182
se_76499573
stackoverflow
DATA_SCIENCE
Assign a list in a pandas dataframe cell: ValueError: Must have equal len keys and value when setting with an iterable
Assign a list in a pandas dataframe cell: ValueError: Must have equal len keys and value when setting with an iterable I was trying to df.at[100, 'subjects'] The result is [] which indicates the index is unique. But when I tried to replace the empty list to a new one: df.at[100, 'subjects'] = [1,2,3] the error occu...
https://stackoverflow.com/questions/76499573/assign-a-list-in-a-pandas-dataframe-cell-valueerror-must-have-equal-len-keys-a
python, pandas, dataframe
1,687,075,518
se_79833941
stackoverflow
DATA_SCIENCE
Put all row from a data in a list
Put all row from a data in a list I am having a problem to put an entire row from data in a list import pandas as pd import numpy as np import csv df= pd.read_csv ("data.csv") my_list = [] # list for n in range(1, len(df)): #entire data if df.loc[n].isin([1]).any() : # if a value 1 is found in any r...
https://stackoverflow.com/questions/79833941/put-all-row-from-a-data-in-a-list
python, pandas, dataframe, for-loop
1,764,511,546
se_79833029
stackoverflow
DATA_SCIENCE
How to modify mulitple columns applying if else to multiple pandas dataframe columns
How to modify mulitple columns applying if else to multiple pandas dataframe columns I have a dataFrame with columns Age, Salary and others, if I used: df['Age'] = df['Age'].apply(lambda x : x+100 if x>30 else 0) Then I can modify the Age column with the if else condition. Also, if I used: df[['Age', 'Salary']] = df[[...
https://stackoverflow.com/questions/79833029/how-to-modify-mulitple-columns-applying-if-else-to-multiple-pandas-dataframe-col
python, pandas, dataframe, lambda, apply
1,764,386,365
se_79833386
stackoverflow
DATA_SCIENCE
Suitable Pandas installation on 32-bit Python (3.10, 3.11)
Suitable Pandas installation on 32-bit Python (3.10, 3.11) I am trying to use the Kiwoom OpenAPI (for making automated stock trading program), which requires a 32-bit Python environment. However, to successfully use Kiwoom Open API I need to set up pandas in any 32-bit Python version, but I can't find how to install p...
https://stackoverflow.com/questions/79833386/suitable-pandas-installation-on-32-bit-python-3-10-3-11
python, pandas, windows, com, 32-bit
1,764,434,726
se_41518920
stackoverflow
DATA_SCIENCE
How to query if a list-type column contains something?
How to query if a list-type column contains something? I have a dataframe, which contains info about movies. It has a column called genre, which contains a list of genres it belongs to. For example: df['genre'] ## returns 0 ['comedy', 'sci-fi'] 1 ['action', 'romance', 'comedy'] 2 ['documentary'] 3 ...
https://stackoverflow.com/questions/41518920/how-to-query-if-a-list-type-column-contains-something
python, pandas, dataframe
1,483,773,448
se_76437122
stackoverflow
DATA_SCIENCE
Pandas.read_sql throw exception from sqlalchemy: AttributeError: &#39;Connection&#39; object has no attribute &#39;exec_driver_sql&#39;
Pandas.read_sql throw exception from sqlalchemy: AttributeError: &#39;Connection&#39; object has no attribute &#39;exec_driver_sql&#39; #pd.version is '2.0.2' #sqlalchemy.version is '1.3.7' import pandas as pd from sqlalchemy import create_engine conn_str = 'connection_string' engine = create_engine(conn_str) Yeste...
https://stackoverflow.com/questions/76437122/pandas-read-sql-throw-exception-from-sqlalchemy-attributeerror-connection-ob
python, pandas, sqlalchemy
1,686,283,206
se_58798989
stackoverflow
DATA_SCIENCE
How to synchronize or merge dataframe with JSON data based on timestamp
How to synchronize or merge dataframe with JSON data based on timestamp There are many examples out there on how to merge two pandas dataframe but my problem is that I have two kind of data. data1 is a csv data that I read it with pandas and turn it to dataframe and the other data2 is in JSON format. Here is an exampl...
https://stackoverflow.com/questions/58798989/how-to-synchronize-or-merge-dataframe-with-json-data-based-on-timestamp
python, json, pandas, dataframe, merge
1,573,465,649
se_79831600
stackoverflow
DATA_SCIENCE
Use pandas merge_asof to achieve inexact left join
Use pandas merge_asof to achieve inexact left join I have two pandas series: right_series Index Value 1 0.1 2 0.2 3 0.3 6 0.6 7 0.7 left_series Index Value 1 0.1 5 0.5 10 1.0 I would like to join right_series on left_series by the indices, such that if an exact match of the index is not...
https://stackoverflow.com/questions/79831600/use-pandas-merge-asof-to-achieve-inexact-left-join
python, pandas, join, merge, left-join
1,764,238,164
se_79829898
stackoverflow
DATA_SCIENCE
How to split dataframe into multiple sub-dataframes based on column value
How to split dataframe into multiple sub-dataframes based on column value I got a dataframe df1 which looks like this: Column1 Column2 13 1 12 1 15 0 16 0 15 1 14 1 12 1 11 0 21 1 45 1 44 0 The 1s indicate that a measurement started, I don't know how many 1s will be in one measurement and...
https://stackoverflow.com/questions/79829898/how-to-split-dataframe-into-multiple-sub-dataframes-based-on-column-value
python, pandas, dataframe
1,764,084,815
se_42513049
stackoverflow
DATA_SCIENCE
Get all keys from GroupBy object in Pandas
Get all keys from GroupBy object in Pandas I'm looking for a way to get a list of all the keys in a GroupBy object, but I can't seem to find one via the docs nor through Google. There is definitely a way to access the groups through their keys, like so: df_gb = df.groupby(['EmployeeNumber']) df_gb.get_group(key) ...
https://stackoverflow.com/questions/42513049/get-all-keys-from-groupby-object-in-pandas
python, pandas
1,488,296,658
se_65488111
stackoverflow
DATA_SCIENCE
Using constant memory with pandas xlsxwriter
Using constant memory with pandas xlsxwriter I'm trying to use the below code to write large pandas dataframes to excel worsheets. If I write it directly, the system is running out of RAM. Is this a viable option or are there any alternatives? writer = pd.ExcelWriter('Python Output Analysis.xlsx', engine='xlsxwriter',...
https://stackoverflow.com/questions/65488111/using-constant-memory-with-pandas-xlsxwriter
python, excel, pandas, xlsxwriter
1,609,222,767
se_79830815
stackoverflow
DATA_SCIENCE
Using list to find variables from data in rows
Using list to find variables from data in rows I am trying to find a combination where it will go through the data to find matched variables for any value from the list First_row is found, any value from the list Second_row and any value from the list Third_row is found. import pandas as pd import numpy as np import c...
https://stackoverflow.com/questions/79830815/using-list-to-find-variables-from-data-in-rows
python, pandas, list, for-loop
1,764,166,857