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_13404468
stackoverflow
DATA_SCIENCE
T-test in Pandas
T-test in Pandas If I want to calculate the mean of two categories in Pandas, I can do it like this: data = {'Category': ['cat2','cat1','cat2','cat1','cat2','cat1','cat2','cat1','cat1','cat1','cat2'], 'values': [1,2,3,1,2,3,1,2,3,5,1]} my_data = DataFrame(data) my_data.groupby('Category').mean() Category: ...
https://stackoverflow.com/questions/13404468/t-test-in-pandas
python, pandas, scipy, statistics, hypothesis-test
1,353,006,717
se_66936732
stackoverflow
DATA_SCIENCE
How to do the ADF Test for each column of my Dataframe in Python?
How to do the ADF Test for each column of my Dataframe in Python? I am looking for a way to do the ADF Test for multiple columns of a DataFrame. Do you have any idea? This is my multi-column dataframe. How to calculate the test for each column separately? Date Acre Amapá Pará Rondônia Roraima Tocantins Alagoas Bahi...
https://stackoverflow.com/questions/66936732/how-to-do-the-adf-test-for-each-column-of-my-dataframe-in-python
python, pandas, dataframe, time-series, data-science
1,617,492,224
se_79907288
stackoverflow
DATA_SCIENCE
Why doesn't copy_on_write work when modifying a copy of an entire DataFrame?
Why doesn't copy_on_write work when modifying a copy of an entire DataFrame? With pd.options.mode.copy_on_write = True, the original should not be modified when writing to a copy. However, when I reassign a column of the copy, it affects the original. import pandas as pd pd.options.mode.copy_on_write = True df = p...
https://stackoverflow.com/questions/79907288/why-doesnt-copy-on-write-work-when-modifying-a-copy-of-an-entire-dataframe
python, pandas, copy-on-write
1,773,452,355
se_48138255
stackoverflow
DATA_SCIENCE
How to change dataframe column in Pandas?
How to change dataframe column in Pandas? I have a dataframe df1 with columns as partnumber and car. EXAMPLE: partnumber car P1 1 P2 2 P3 1 P4 2 partnumber column needs to be stripped to remove whitespaces, if I run: df1['partnumber'] = df1['partnumber'].map(lambda x:str...
https://stackoverflow.com/questions/48138255/how-to-change-dataframe-column-in-pandas
python, pandas
1,515,336,200
se_79860752
stackoverflow
DATA_SCIENCE
"ModuleNotFoundError: No module named 'pandas' " but is present in the python package list and in software manager
"ModuleNotFoundError: No module named 'pandas' " but is present in the python package list and in software manager I've recently switched from Windows 10 to Linux Mint, but after pulling some of my old git projects I'm having issues getting the modules to work correctly. My initial import list looks ...
https://stackoverflow.com/questions/79860752/modulenotfounderror-no-module-named-pandas-but-is-present-in-the-python-pa
python, pandas, linux
1,767,615,142
se_17141558
stackoverflow
DATA_SCIENCE
How to sort a pandas dataFrame by two or more columns?
How to sort a pandas dataFrame by two or more columns? Suppose I have a dataframe with columns a, b and c. I want to sort the dataframe by column b in ascending order, and by column c in descending order. How do I do this?
https://stackoverflow.com/questions/17141558/how-to-sort-a-pandas-dataframe-by-two-or-more-columns
python, pandas, dataframe, sorting, data-analysis
1,371,450,527
se_32037802
stackoverflow
DATA_SCIENCE
Find target values in pandas dataframe
Find target values in pandas dataframe I have a multilevel dataframe df. As columns, I have different "objects" I analyze. As rows index, I have a Case ID lc, and time t. I need to find, for each case lc, the time t (ideally interpolated, but closest value is fine enough) at which each object reached a target value. T...
https://stackoverflow.com/questions/32037802/find-target-values-in-pandas-dataframe
python, pandas
1,439,745,047
se_41560021
stackoverflow
DATA_SCIENCE
Error "'numpy.ndarray' object has no attribute 'values'"
Error "'numpy.ndarray' object has no attribute 'values'" I want to shift my time series data, but I am getting the following error: AttributeError: 'numpy.ndarray' object has no attribute 'values' This is my code: def create_dataset(datasets): #series = dataset temps = DataFrame(data...
https://stackoverflow.com/questions/41560021/error-numpy-ndarray-object-has-no-attribute-values
python, pandas, numpy
1,484,013,909
se_47990797
stackoverflow
DATA_SCIENCE
pandas - cumulative median
pandas - cumulative median I was wondering if there is any pandas equivalent to cumsum() or cummax() etc. for median: e.g. cummedian(). So that if I have, for example this dataframe: a 1 5 2 7 3 6 4 4 what I want is something like: df['a'].cummedian() which should output: 5 6 6 5.5
https://stackoverflow.com/questions/47990797/pandas-cumulative-median
python, pandas, math, accumulate
1,514,371,572
se_44302726
stackoverflow
DATA_SCIENCE
Pandas: How to store cProfile output in a pandas DataFrame?
Pandas: How to store cProfile output in a pandas DataFrame? There already exist some posts discussing python profiling using cProfile, as well as the challenges of analyzing the output due to the fact that the output file restats from the sample code below is not a plain text file. The snippet below is only a sample f...
https://stackoverflow.com/questions/44302726/pandas-how-to-store-cprofile-output-in-a-pandas-dataframe
python, pandas, profiling
1,496,306,924
se_43877692
stackoverflow
DATA_SCIENCE
Pandas in AWS lambda gives numpy error
Pandas in AWS lambda gives numpy error I've been trying to run my code in AWS Lambda which imports pandas. So here is what I've done. I have a python file which contains a simple code as follows(This file has the lambda handler) import json print('Loading function') import pandas as pd def lambda_handler(event, conte...
https://stackoverflow.com/questions/43877692/pandas-in-aws-lambda-gives-numpy-error
python, pandas, numpy, amazon-s3, aws-lambda
1,494,355,736
se_79903511
stackoverflow
DATA_SCIENCE
Pandas groupby monthly within date range of dataframe, start date and end date
Pandas groupby monthly within date range of dataframe, start date and end date My groupby monthly, displays the graph from start of month, which has a sales value of Zero, because there are no records for that date. I need the graph to show from date of first record in dataframe. And likewise for last date in datafram...
https://stackoverflow.com/questions/79903511/pandas-groupby-monthly-within-date-range-of-dataframe-start-date-and-end-date
python, pandas, dataframe, group-by
1,773,012,794
se_79448603
stackoverflow
DATA_SCIENCE
How to convert a pandas dataframe to numeric future proof?
How to convert a pandas dataframe to numeric future proof? Until now I used to convert all values in a pandas dataframe with combined numerical and string entries to numeric values if possible in one easy step, using .map and .to_numeric with "errors = 'ignore'". It worked perfectly, but after updating to the latest v...
https://stackoverflow.com/questions/79448603/how-to-convert-a-pandas-dataframe-to-numeric-future-proof
python, pandas, dataframe, error-handling, deprecation-warning
1,739,889,111
se_57626096
stackoverflow
DATA_SCIENCE
Pandas DF NotImplementedError: Writing to Excel with MultiIndex columns and no index ('index'=False) is not yet implemented
Pandas DF NotImplementedError: Writing to Excel with MultiIndex columns and no index ('index'=False) is not yet implemented I have these lines of code reading and writing an excel: df = pd.read_excel(file_path, sheet_name, header=[0, 1]) df.to_excel(output_path, index=False) When it tries to write the excel...
https://stackoverflow.com/questions/57626096/pandas-df-notimplementederror-writing-to-excel-with-multiindex-columns-and-no-i
python, pandas, dataframe
1,566,562,281
se_79897904
stackoverflow
DATA_SCIENCE
Plotly Choropleth Map: Data points not showing up randomly in the map
Plotly Choropleth Map: Data points not showing up randomly in the map I am trying to create an animated choropleth map using Plotly that shows when certain countries legalised a policy. So basically, the map is animated to show each year and countries are coloured different colours based on if they legalised a policy,...
https://stackoverflow.com/questions/79897904/plotly-choropleth-map-data-points-not-showing-up-randomly-in-the-map
python, pandas, plotly, choropleth
1,772,204,944
se_17326973
stackoverflow
DATA_SCIENCE
Is there a way to auto-adjust Excel column widths with pandas.ExcelWriter?
Is there a way to auto-adjust Excel column widths with pandas.ExcelWriter? I am being asked to generate some Excel reports. I am currently using pandas quite heavily for my data, so naturally I would like to use the pandas.ExcelWriter method to generate these reports. However the fixed column widths are a problem. Th...
https://stackoverflow.com/questions/17326973/is-there-a-way-to-auto-adjust-excel-column-widths-with-pandas-excelwriter
python, excel, pandas, openpyxl
1,372,268,648
se_79902824
stackoverflow
DATA_SCIENCE
What would be the best way to drop pandas dataframe rows based on an index condition with a MultiIndex?
What would be the best way to drop pandas dataframe rows based on an index condition with a MultiIndex? I have a dataframe with two index levels from a stack operation, and I'd like to then drop rows based on a condition for the index. Currently, what I've got goes something like this: import pandas as pd import numpy...
https://stackoverflow.com/questions/79902824/what-would-be-the-best-way-to-drop-pandas-dataframe-rows-based-on-an-index-condi
python, pandas, dataframe, multi-index
1,772,893,617
se_75791799
stackoverflow
DATA_SCIENCE
I have one for condition, and can't do if statement to count cell condition
I have one for condition, and can't do if statement to count cell condition I'm trying to do this condition to count how many times (cells) have values less than 300 seconds (5 minutes) but I get an error, the condition is about a DF below, that I pull from my csv: df = 0 0 NaN 1 79.0 2 140.0 3 131.0 4...
https://stackoverflow.com/questions/75791799/i-have-one-for-condition-and-cant-do-if-statement-to-count-cell-condition
python, pandas, numpy, if-statement, conditional-statements
1,679,323,825
se_79901699
stackoverflow
DATA_SCIENCE
What do you do when you want to split column but your dataframe was fused and transposed, and that column is now an index?
What do you do when you want to split column but your dataframe was fused and transposed, and that column is now an index? I have been analysing antimicrobial resistance genes in foodborne pathogens. For the next analysis, I need to compare different types of foods. So I wrote a code that counts each AMR gene in diffe...
https://stackoverflow.com/questions/79901699/what-do-you-do-when-you-want-to-split-column-but-your-dataframe-was-fused-and-tr
python, pandas, dataframe
1,772,725,241
se_75451378
stackoverflow
DATA_SCIENCE
Modify a bar plot into a stacked plot keeping the original values
Modify a bar plot into a stacked plot keeping the original values I have a pandas DataFrame containing the percentage of students that have a certain skill in each subject stratified according to their gender iterables = [['Above basic','Basic','Low'], ['Female','Male']] index = pd.MultiIndex.from_product(iterables, n...
https://stackoverflow.com/questions/75451378/modify-a-bar-plot-into-a-stacked-plot-keeping-the-original-values
python, pandas, matplotlib, bar-chart, plot-annotations
1,676,396,133
se_17578115
stackoverflow
DATA_SCIENCE
Pass percentiles to pandas agg function
Pass percentiles to pandas agg function I want to pass the numpy percentile() function through pandas' agg() function as I do below with various other numpy statistics functions. Right now I have a dataframe that looks like this: AGGREGATE MY_COLUMN A 10 A 12 B 5 B 9 A ...
https://stackoverflow.com/questions/17578115/pass-percentiles-to-pandas-agg-function
python, pandas, numpy, aggregate
1,373,480,566
se_47100160
stackoverflow
DATA_SCIENCE
Use dataframe groupby agg within a 'for' loop with predefined functions
Use dataframe groupby agg within a 'for' loop with predefined functions How would like to execute the following for loop: operation = ['mean','std'] for i in range(0,len(operation)): df2 = df.groupby(level='Index').agg(operation[i]).dropna(how='all') .... But using the function from NumPy: operation =...
https://stackoverflow.com/questions/47100160/use-dataframe-groupby-agg-within-a-for-loop-with-predefined-functions
python, pandas, numpy, group-by
1,509,725,768
se_53979403
stackoverflow
DATA_SCIENCE
Search for a value anywhere in a pandas DataFrame
Search for a value anywhere in a pandas DataFrame This seems like a simple question, but I couldn't find it asked before (this and this are close but the answers aren't great). The question is: if I want to search for a value somewhere in my df (I don't know which column it's in) and return all rows with a match. ...
https://stackoverflow.com/questions/53979403/search-for-a-value-anywhere-in-a-pandas-dataframe
python, pandas, dataframe
1,546,187,575
se_40185437
stackoverflow
DATA_SCIENCE
No module named 'numpy': Visual Studio Code
No module named 'numpy': Visual Studio Code I'm trying to setup Visual Studio Code for python development to begin with, I've installed Anaconda Python Visual Studio Code and in a new file I have the following code import numpy as np import pandas as pd from pandas import Series, DataFrame upon hittin...
https://stackoverflow.com/questions/40185437/no-module-named-numpy-visual-studio-code
python, pandas, numpy, visual-studio-code
1,477,083,898
se_79901475
stackoverflow
DATA_SCIENCE
How to not get Invalid Date after inserting into snowflake DB
How to not get Invalid Date after inserting into snowflake DB I have a pandas dataframe named "df". The dataframe has two columns (CREATEDDATE and LASTMODIFIEDDATE) which contain datetime values. When i try to insert using this df into snowflake db,the datetime values turn into - Invalid date. this is the code i am us...
https://stackoverflow.com/questions/79901475/how-to-not-get-invalid-date-after-inserting-into-snowflake-db
python, sql, pandas, snowflake-cloud-data-platform
1,772,706,417
se_61948103
stackoverflow
DATA_SCIENCE
Conditional merge / join of two large Pandas DataFrames with duplicated keys based on values of multiple columns
Conditional merge / join of two large Pandas DataFrames with duplicated keys based on values of multiple columns I come from R and honestly, this is the simplest thing to do in one line using R data.tables, and the operation is also quite fast for large datatables. Bu I'm really struggling implementing it in Python. N...
https://stackoverflow.com/questions/61948103/conditional-merge-join-of-two-large-pandas-dataframes-with-duplicated-keys-bas
python, pandas, dataframe, merge, large-data
1,590,123,283
se_77162585
stackoverflow
DATA_SCIENCE
Allocate resources on tasks
Allocate resources on tasks I'm working on a Resource-Task allocation problem that considers 2 datasets: for each Resource and month I have availability (in working days) for each Task I need certain working days Is there any possibility in Python to be able to randomly allocate my IDs on certain Tasks (only for a m...
https://stackoverflow.com/questions/77162585/allocate-resources-on-tasks
python, pandas, dataframe
1,695,464,537
se_79900176
stackoverflow
DATA_SCIENCE
How to maintain feature alignment when passing a custom model wrapper to SHAP KernelExplainer?
How to maintain feature alignment when passing a custom model wrapper to SHAP KernelExplainer? I'm working on an Explainable AI (XAI) project where I compare different model-agnostic frameworks (SHAP, LIME, DALEX). I'm using a custom wrapper to standardize my model's output (similar to a Scikit-Learn pipeline) to ensu...
https://stackoverflow.com/questions/79900176/how-to-maintain-feature-alignment-when-passing-a-custom-model-wrapper-to-shap-ke
python, pandas, scikit-learn
1,772,546,110
se_79900760
stackoverflow
DATA_SCIENCE
dict to dataframe to export in Excel
dict to dataframe to export in Excel I am trying to convert a dict in a df in order to export it into Excel. Since I cannot export a list of dict I need to convert it in df. However, I have an issue with my columns/index, if I understand correctly, I have several columns with the same name which is not possible within...
https://stackoverflow.com/questions/79900760/dict-to-dataframe-to-export-in-excel
python, excel, pandas, dataframe
1,772,620,130
se_75276555
stackoverflow
DATA_SCIENCE
Split a pandasframe into X groups each with an average value of Y
Split a pandasframe into X groups each with an average value of Y Really wish I would've paid more attention to statistics in college, maybe I'd remember something for this. Regardless, I have a dataset with approx ~4800 rows, and I want to group this dataset into 8 groups, however I'd like this final dataset to have ...
https://stackoverflow.com/questions/75276555/split-a-pandasframe-into-x-groups-each-with-an-average-value-of-y
python, pandas, statistics
1,675,010,377
se_79899165
stackoverflow
DATA_SCIENCE
Using matplotlib to build report of survey responses, what is the most efficient way to tally likert scores?
Using matplotlib to build report of survey responses, what is the most efficient way to tally likert scores? I am building out functionality in an existing app for a user to upload an excel file to plot out responses for survey questions. There are 4 likert questions with 2 comment response question. The relevant data...
https://stackoverflow.com/questions/79899165/using-matplotlib-to-build-report-of-survey-responses-what-is-the-most-efficient
python, pandas, dataframe, matplotlib
1,772,421,533
se_72556514
stackoverflow
DATA_SCIENCE
how to solve 'Expect x to not have duplicates' with scipy?
how to solve 'Expect x to not have duplicates' with scipy? i was trying to make curve as follows: x = all_dat['rcs'] y = all_dat['Mean_Range'] xnew = np.linspace(x.min(), x.max(), 200) cubic_interploation_model = interp1d(x, y, kind = "cubic") y_=cubic_interploation_model(xnew) pl.plot(...
https://stackoverflow.com/questions/72556514/how-to-solve-expect-x-to-not-have-duplicates-with-scipy
python, pandas, dataframe, matplotlib, scipy
1,654,760,805
se_68532300
stackoverflow
DATA_SCIENCE
Cannabis Page Scrape, Awkward layout
Cannabis Page Scrape, Awkward layout The page I am trying to scrape is https://agco.maps.arcgis.com/apps/webappviewer/index.html?id=bef894bc0876448fba26333f1de8d370. From this page I am trying to get 5 types of data, Name of dispenser, address, Postal ( Ex.N4K 5N6), Status and Public Notice date. My problem is I have ...
https://stackoverflow.com/questions/68532300/cannabis-page-scrape-awkward-layout
python, html, pandas, web-scraping, beautifulsoup
1,627,312,113
se_73816269
stackoverflow
DATA_SCIENCE
incremental counter to a dataframe based on unique values from a column
incremental counter to a dataframe based on unique values from a column Existing Dataframe : Unique_Id sms_sent_date A 11-01-2022 A 11-01-2022 A 12-01-2022 A 13-01-2022...
https://stackoverflow.com/questions/73816269/incremental-counter-to-a-dataframe-based-on-unique-values-from-a-column
python, pandas, dataframe
1,663,856,372
se_79898053
stackoverflow
DATA_SCIENCE
How to remove column name from facet titles in Plotly Express histogram
How to remove column name from facet titles in Plotly Express histogram import plotly.express as px import pandas as pd df = pd.DataFrame({ "country": ['Poland', 'Poland', 'Poland', 'Germany', 'Germany', 'Germany', 'France', 'France', 'France'], "city": ['Warsaw', 'Krakow', 'Gd...
https://stackoverflow.com/questions/79898053/how-to-remove-column-name-from-facet-titles-in-plotly-express-histogram
python, pandas, plotly, histogram
1,772,217,832
se_76979303
stackoverflow
DATA_SCIENCE
Pandas: filter dataframe by column of sets using multiple conditions regarding substrings
Pandas: filter dataframe by column of sets using multiple conditions regarding substrings I have a problem whereby I want to filter the following dataframe such that I only return the rows where we have both a pie and a non-pie item: ID set 1 apple pie, banana loaf 2 banana pie, apple pie 3 banana loaf, ap...
https://stackoverflow.com/questions/76979303/pandas-filter-dataframe-by-column-of-sets-using-multiple-conditions-regarding-s
python, pandas, set
1,692,983,666
se_79749411
stackoverflow
DATA_SCIENCE
What is NaT in Pandas?
What is NaT in Pandas? I have a dataframe with some "NaT" values in a datetime column. What does that mean? project status completed 0 windows done 2025-08-20 1 doors done 2025-08-21 2 hvac delayed NaT I checked the docs page pandas.NaT, but it just says "alias of NaT", which doesn't see...
https://stackoverflow.com/questions/79749411/what-is-nat-in-pandas
python, pandas, datetime
1,756,400,923
se_79897242
stackoverflow
DATA_SCIENCE
Combining multiple spreadsheets through Pandas and I'm trying to get multiple columns in one and it appears to only take one column per sheet
Combining multiple spreadsheets through Pandas and I'm trying to get multiple columns in one and it appears to only take one column per sheet I had a similar problem posted here previously but I think explained poorly so I will try and condense it here. I have multiple spreadsheets ranging from 2019 to 2023 contai...
https://stackoverflow.com/questions/79897242/combining-multiple-spreadsheets-through-pandas-and-im-trying-to-get-multiple-co
python, excel, pandas, dataframe
1,772,124,181
se_79892563
stackoverflow
DATA_SCIENCE
New dataframe column based on comparison with another dataframe
New dataframe column based on comparison with another dataframe Let's say I have the following two dataframes, which contain some common information: import pandas as pd df_1 = pd.DataFrame({ "first_name": ["Alice", "Bob", "Charlie", "Alice"], "age": [15, 16, 15, 17], "last_name": ["Smith", "Smith", "Jone...
https://stackoverflow.com/questions/79892563/new-dataframe-column-based-on-comparison-with-another-dataframe
python, pandas, dataframe
1,771,541,213
se_72177022
stackoverflow
DATA_SCIENCE
How to get hash of string column in Polars or Pyarrow
How to get hash of string column in Polars or Pyarrow I have a Pandas DataFrame/Polars dataframe / Pyarrow table with a string key column. You can assume the strings are random. I want to partition that dataframe into N smaller dataframes based on this key column. With an integer column, I can just use df1 = df[df.key...
https://stackoverflow.com/questions/72177022/how-to-get-hash-of-string-column-in-polars-or-pyarrow
python, pandas, dataframe, python-polars, pyarrow
1,652,122,902
se_77169878
stackoverflow
DATA_SCIENCE
Using polars is indeed faster than pandas 2 BUT NOT parquet file and either case memory usage is the same as pandas 2
Using polars is indeed faster than pandas 2 BUT NOT parquet file and either case memory usage is the same as pandas 2 I am considering moving from pandas to polars. so I am doing some comparison for my big csv reading. The file size of csv is around 600MB. The message is: even using pandas 2, using pandas 2 without p...
https://stackoverflow.com/questions/77169878/using-polars-is-indeed-faster-than-pandas-2-but-not-parquet-file-and-either-case
python, pandas, dataframe, csv, python-polars
1,695,615,354
se_71657556
stackoverflow
DATA_SCIENCE
Error while converting pandas dataframe to polars dataframe (pyarrow.lib.ArrowTypeError: Expected bytes, got a 'int' object)
Error while converting pandas dataframe to polars dataframe (pyarrow.lib.ArrowTypeError: Expected bytes, got a 'int' object) I am converting pandas dataframe to polars dataframe but pyarrow throws error. My code: import polars as pl import pandas as pd if __name__ == "__main__": with open(r"test.xlsx", "...
https://stackoverflow.com/questions/71657556/error-while-converting-pandas-dataframe-to-polars-dataframe-pyarrow-lib-arrowty
python, excel, pandas, dataframe, python-polars
1,648,536,274
se_67910612
stackoverflow
DATA_SCIENCE
Arrow IPC vs Feather
Arrow IPC vs Feather What is the difference between Arrow IPC and Feather? The official Arrow documentation has this to say about Feather: Version 2 (V2), the default version, which is exactly represented as the Arrow IPC file format on disk. V2 files support storing all Arrow data types as well as compression with L...
https://stackoverflow.com/questions/67910612/arrow-ipc-vs-feather
pandas, python-polars, apache-arrow, vaex, feather
1,623,267,103
se_76235344
stackoverflow
DATA_SCIENCE
Reading a file with Polars that has been created as a TAD file and has sep='\t', lineterminator='\r'
Reading a file with Polars that has been created as a TAD file and has sep='\t', lineterminator='\r' I can read a dataframe like this in pandas (it was originally a TAD file): pd.read_csv('/content/drive/MyDrive/Database Nencini/estrapola_articoli.csv', sep='\t', lineterminator='\r') How can I do it u...
https://stackoverflow.com/questions/76235344/reading-a-file-with-polars-that-has-been-created-as-a-tad-file-and-has-sep-t
pandas, dataframe, python-polars
1,683,886,970
se_79484795
stackoverflow
DATA_SCIENCE
Python Pandas - Prior Price Change Date based on Multiple Columns
Python Pandas - Prior Price Change Date based on Multiple Columns I've done my due diligence and still can't find what I need to make this happen. This is a sample dataset of what I'm using. I need to add the column "date_price_change" for that particular Store/SKU combination where the "price" changed last. I've tri...
https://stackoverflow.com/questions/79484795/python-pandas-prior-price-change-date-based-on-multiple-columns
python, pandas, lambda, group-by
1,741,120,313
se_31269216
stackoverflow
DATA_SCIENCE
Applying uppercase to a column in pandas dataframe
Applying uppercase to a column in pandas dataframe I'm having trouble applying upper case to a column in my DataFrame. dataframe is df. 1/2 ID is the column head that need to apply UPPERCASE. The problem is that the values are made up of three letters and three numbers. For example rrr123 is one of the values. df[...
https://stackoverflow.com/questions/31269216/applying-uppercase-to-a-column-in-pandas-dataframe
python, pandas, string, dataframe
1,436,273,994
se_66214951
stackoverflow
DATA_SCIENCE
Deal with openpyxl warning: "Workbook contains no default style, apply openpyxl's default "
Deal with openpyxl warning: "Workbook contains no default style, apply openpyxl's default " I have the -current- latest version of pandas, openpyxl, xlrd. openpyxl : 3.0.6. pandas : 1.2.2. xlrd : 2.0.1. I have a generated excel xlsx- file (export from a webapplication). I read it in pandas: myexcelfile =...
https://stackoverflow.com/questions/66214951/deal-with-openpyxl-warning-workbook-contains-no-default-style-apply-openpyxl
python, pandas, openpyxl
1,613,420,844
se_79896089
stackoverflow
DATA_SCIENCE
Register metadata in accessor that survives pipes
Register metadata in accessor that survives pipes I'm trying to combine pandas custom accessors and defining original properties. I would like an original property to be defined in an accessor and to survive pipe operations. Consider the following example: import pandas as pd @pd.api.extensions.register_dataframe_acc...
https://stackoverflow.com/questions/79896089/register-metadata-in-accessor-that-survives-pipes
python, pandas
1,772,014,576
se_79895203
stackoverflow
DATA_SCIENCE
Pandas dataframe conditional value assignemnt leads to error when there are exactly 2 rows in the dataframe
Pandas dataframe conditional value assignemnt leads to error when there are exactly 2 rows in the dataframe I'm facing an issue with pandas. Assign values based on conditional fails for the case that I have exactly 2 rows and they both meet the same condition. If they meet different conditions it also works or for an...
https://stackoverflow.com/questions/79895203/pandas-dataframe-conditional-value-assignemnt-leads-to-error-when-there-are-exac
python, pandas
1,771,918,064
se_59882714
stackoverflow
DATA_SCIENCE
Python pandas generating a list of dates between two dates
Python pandas generating a list of dates between two dates I want to generate a list of dates between two dates and store them in a list in string format. This list is useful to compare with other dates I have. My code is given below: from datetime import date, timedelta sdate = date(2019,3,22) # start date eda...
https://stackoverflow.com/questions/59882714/python-pandas-generating-a-list-of-dates-between-two-dates
python, pandas, datetime, date-range
1,579,795,640
se_28654047
stackoverflow
DATA_SCIENCE
Convert some columns into rows with Pandas
Convert some columns into rows with Pandas So my dataset has some information by location for n dates. The problem is each date is actually a different column header. For example the CSV looks like location name Jan-2010 Feb-2010 March-2010 A "test" 12 20 30 B "foo" ...
https://stackoverflow.com/questions/28654047/convert-some-columns-into-rows-with-pandas
python, pandas
1,424,574,508
se_76546838
stackoverflow
DATA_SCIENCE
Why is streamlit messing up my Plotly chart?
Why is streamlit messing up my Plotly chart? Importing the streamlit library into my Python code has changed my Plotly chart into black and white. The same description can also be found on the Plotly github page. My problem can be replicated with the following steps: First of all, I have the following system configura...
https://stackoverflow.com/questions/76546838/why-is-streamlit-messing-up-my-plotly-chart
python, pandas, plotly, streamlit
1,687,621,577
se_43890875
stackoverflow
DATA_SCIENCE
Pandas to_numeric with option errors=ignore does not convert to float
Pandas to_numeric with option errors=ignore does not convert to float I wanted to convert pandas series from object to float but keep other strings as it is. Here is the code snippet :- In [37]: df = pd.DataFrame(['-1.0', 'hello', '0.5']) In [38]: df[0] Out[38]: 0 -1.0 1 hello 2 0.5 Name: 0, dtype: object ...
https://stackoverflow.com/questions/43890875/pandas-to-numeric-with-option-errors-ignore-does-not-convert-to-float
python, pandas
1,494,414,915
se_79893512
stackoverflow
DATA_SCIENCE
Create new column in yf dataframe not possible?
Create new column in yf dataframe not possible? I would like to create a new column in a yfinance dataframe using the following code: import yfinance as yf df = yf.download("NVDA", period="3y", interval="1wk") spy = yf.download("SPY", period="3y", interval="1wk")['Close'] df['RS_Ratio'] = df['Close'] / spy But i allw...
https://stackoverflow.com/questions/79893512/create-new-column-in-yf-dataframe-not-possible
python, pandas, dataframe, multi-index, yfinance
1,771,673,804
se_69500841
stackoverflow
DATA_SCIENCE
Excel file format cannot be determined with Pandas, randomly happening
Excel file format cannot be determined with Pandas, randomly happening I have a script that edits an xlsx file I've been running weekly successfully for a year and a half, up until last week when this error started to occur: Excel file format cannot be determined, you must specify an engine manually. df = pd.read_exce...
https://stackoverflow.com/questions/69500841/excel-file-format-cannot-be-determined-with-pandas-randomly-happening
python, pandas
1,633,720,987
se_79892823
stackoverflow
DATA_SCIENCE
Removing Series content from another Series
Removing Series content from another Series I am working on a report where two columns are Hostname and Domain. The issue is that some hostnames contain the domain so I want to standardize and clean it. I've tried str.rstrip and str.removesuffix but both return an empty column. import pandas as pd df = pd.read_excel(...
https://stackoverflow.com/questions/79892823/removing-series-content-from-another-series
python, pandas
1,771,581,299
se_63768373
stackoverflow
DATA_SCIENCE
Pandas concat keeps adding new index columns
Pandas concat keeps adding new index columns I'm pretty new to Python and Pandas, and having a concat(?)-problem with my small project. The code works almost as it's meant to work, but when running it multiple times in a row, it keeps adding new index-columns. This is something I don't want it to do. I've been trying ...
https://stackoverflow.com/questions/63768373/pandas-concat-keeps-adding-new-index-columns
python, pandas, concatenation
1,599,422,325
se_16476924
stackoverflow
DATA_SCIENCE
How can I iterate over rows in a Pandas DataFrame?
How can I iterate over rows in a Pandas DataFrame? I have a pandas dataframe, df: c1 c2 0 10 100 1 11 110 2 12 120 How do I iterate over the rows of this dataframe? For every row, I want to access its elements (values in cells) by the name of the columns. For example: for row in df.rows: print(row['c1'...
https://stackoverflow.com/questions/16476924/how-can-i-iterate-over-rows-in-a-pandas-dataframe
python, pandas, dataframe, loops
1,368,169,489
se_66320966
stackoverflow
DATA_SCIENCE
Pyspark toPandas() Out of bounds nanosecond timestamp error
Pyspark toPandas() Out of bounds nanosecond timestamp error I am trying to convert a Spark DataFrame to Pandas. However, it is giving the following error: OutOfBoundsDatetime: Out of bounds nanosecond timestamp: Is there a work around for this? It works if I drop all timestamp columns, but I would like to bring the wh...
https://stackoverflow.com/questions/66320966/pyspark-topandas-out-of-bounds-nanosecond-timestamp-error
python, pandas, apache-spark, pyspark, apache-spark-sql
1,614,016,668
se_79814464
stackoverflow
DATA_SCIENCE
How to get value of cell in dataframe
How to get value of cell in dataframe I want to read the value of a single cell from a dataframe based on the selected row. I do this as below, but I get the value not when I click on a record (when the selection checkbox is checked), but only after I click on another one or uncheck the row. Why? I get some record fro...
https://stackoverflow.com/questions/79814464/how-to-get-value-of-cell-in-dataframe
python, pandas, dataframe, streamlit
1,762,637,685
se_72535853
stackoverflow
DATA_SCIENCE
How to assign to column with non-string "name" or index?
How to assign to column with non-string "name" or index? Pandas DataFrames have a method assign which will assign values to a column, and which differs from methods like loc or iloc in that it returns a DataFrame with the newly assigned column(s) without modifying any shallow copies or references to the same...
https://stackoverflow.com/questions/72535853/how-to-assign-to-column-with-non-string-name-or-index
python, pandas, dataframe
1,654,625,719
se_21752399
stackoverflow
DATA_SCIENCE
Add a 'total' row to the end of a Pandas DataFrame
Add a 'total' row to the end of a Pandas DataFrame I have a dataframe, something like: foo bar qux 0 a 1 3.14 1 b 3 2.72 2 c 2 1.62 3 d 9 1.41 4 e 3 0.58 and I would like to add a 'total' row to the end of dataframe: foo bar qux 0 a 1 3.14 1 ...
https://stackoverflow.com/questions/21752399/add-a-total-row-to-the-end-of-a-pandas-dataframe
python, pandas, dataframe
1,392,289,580
se_58265633
stackoverflow
DATA_SCIENCE
What's the difference between df.iloc[:,1:2].values and df.iloc[:,1].values in pandas?
What's the difference between df.iloc[:,1:2].values and df.iloc[:,1].values in pandas? When I used x = dataset.iloc[:,1:2].values and later on in my code import pandas as pd import matplotlib.pyplot as plt import numpy as np dataset = pd.read_csv('Position_Salaries.csv') x = dataset.iloc[:,1:2].values #look here p...
https://stackoverflow.com/questions/58265633/whats-the-difference-between-df-iloc-12-values-and-df-iloc-1-values-in-p
python, pandas, scikit-learn
1,570,435,660
se_79638394
stackoverflow
DATA_SCIENCE
Streamlit st.selectbox not displaying options from .txt file
Streamlit st.selectbox not displaying options from .txt file I'm having an issue with Streamlit's st.selectbox not displaying the options I have stored in a .txt file. Here's how I'm trying to implement it: I have a .txt file that contains many lines, each line being a question like: What is the total number of custom...
https://stackoverflow.com/questions/79638394/streamlit-st-selectbox-not-displaying-options-from-txt-file
python, pandas, drop-down-menu, streamlit
1,748,239,790
se_13636848
stackoverflow
DATA_SCIENCE
Is it possible to do fuzzy match merge with pandas?
Is it possible to do fuzzy match merge with pandas? I have two DataFrames which I want to merge based on a column. However, due to alternate spellings, different number of spaces, absence/presence of diacritical marks, I would like to be able to merge as long as they are similar to one another. Any similarity algorith...
https://stackoverflow.com/questions/13636848/is-it-possible-to-do-fuzzy-match-merge-with-pandas
python, pandas
1,354,232,657
se_78276174
stackoverflow
DATA_SCIENCE
Post a pandas dataframe from Jupyter Notebook into Stack Overflow
Post a pandas dataframe from Jupyter Notebook into Stack Overflow What are the steps to post a Pandas dataframe in a Stack Overflow question? I found: How to make good reproducible pandas examples. I followed the instructions and used pd.read_clipboard, but I still had to spend a significant amount of time formatting ...
https://stackoverflow.com/questions/78276174/post-a-pandas-dataframe-from-jupyter-notebook-into-stack-overflow
python, pandas
1,712,258,411
se_76433305
stackoverflow
DATA_SCIENCE
Merging data frames on column with string partial match
Merging data frames on column with string partial match I am attempting to merge two data frames on the column "Name". The names are relatively the same. The merge is not working because there are discrepancies between the names due to special characters, missing suffixes, and nicknames. Any ideas? df1 Name Perfor...
https://stackoverflow.com/questions/76433305/merging-data-frames-on-column-with-string-partial-match
python, pandas, dataframe, fuzzy-search
1,686,237,020
se_55189818
stackoverflow
DATA_SCIENCE
Getting unique values from Pandas column of 2d array cells
Getting unique values from Pandas column of 2d array cells I have a Pandas dataframe where each cell in a column is a 2d array of items. Observation 1 has column items with values ['Baseball', 'Glove','Snack']. When I use .unique on the individual cells, each cell gets analyzed based on the whole array's value, not in...
https://stackoverflow.com/questions/55189818/getting-unique-values-from-pandas-column-of-2d-array-cells
python, pandas
1,552,679,594
se_71104458
stackoverflow
DATA_SCIENCE
How to replace em dash in a dataframe?
How to replace em dash in a dataframe? I am trying to remove the 'em dash' from a pandas DataFrame. I have tried a bunch of different suggestions. But none of them are working. This is what I have got # -*- coding: utf-8 -*- my_str = 'word—word' # my_str.replace(b'\xe2\x80\x94'.decode('utf-8'), '--') my_str.replace('...
https://stackoverflow.com/questions/71104458/how-to-replace-em-dash-in-a-dataframe
python, pandas
1,644,783,087
se_57812453
stackoverflow
DATA_SCIENCE
MemoryError: Unable to allocate array with shape and data type object
MemoryError: Unable to allocate array with shape and data type object I want to perform an inner join between two dataset which looks like: theme_ids.head() id Loan Theme ID Loan Theme Type Partner ID 0 638631 a1050000000skGl General 151 1 640322 a1050000000skGl General 151 2 641006 a1050000002X1ij Higher ...
https://stackoverflow.com/questions/57812453/memoryerror-unable-to-allocate-array-with-shape-and-data-type-object
python, pandas, numpy
1,567,714,612
se_43516982
stackoverflow
DATA_SCIENCE
Import Kaggle csv from download url to pandas DataFrame
Import Kaggle csv from download url to pandas DataFrame I've been trying different methods to import the SpaceX missions csv file on Kaggle directly into a pandas DataFrame, without any success. I'd need to send requests to login. This is what I have so far: import requests import pandas as pd from io import StringI...
https://stackoverflow.com/questions/43516982/import-kaggle-csv-from-download-url-to-pandas-dataframe
python, pandas, csv, python-requests, kaggle
1,492,684,201
se_69216137
stackoverflow
DATA_SCIENCE
Import csv from Kaggle url into a pandas DataFrame
Import csv from Kaggle url into a pandas DataFrame I want to import a public dataset from Kaggle (https://www.kaggle.com/unsdsn/world-happiness?select=2017.csv) into a local jupyter notebook. I don't want to use any credencials in the process. I saw diverse solutions including: pd.read_html, pd.read_csv, pd.read_table...
https://stackoverflow.com/questions/69216137/import-csv-from-kaggle-url-into-a-pandas-dataframe
python, pandas, kaggle
1,631,834,144
se_78307173
stackoverflow
DATA_SCIENCE
Dealing with duplicates cols on duckdb with gaps (nulls) and filling them efficiently
Dealing with duplicates cols on duckdb with gaps (nulls) and filling them efficiently I'm new to duckdb (v0.10.1) so this question comes from my lack of knowledge of the built-in functionality that duckdb has. I have a special use case that I haven't found a cleaver way to do this with duckdb with timeseries data. Som...
https://stackoverflow.com/questions/78307173/dealing-with-duplicates-cols-on-duckdb-with-gaps-nulls-and-filling-them-effici
python, sql, pandas, dataframe, duckdb
1,712,784,073
se_73383536
stackoverflow
DATA_SCIENCE
DuckDB - efficiently insert pandas dataframe to table with sequence
DuckDB - efficiently insert pandas dataframe to table with sequence CREATE TABLE temp ( id UINTEGER, name VARCHAR, age UINTEGER ); CREATE SEQUENCE serial START 1; Insertion with series works just fine: INSERT INTO temp VALUES(nextval('serial'), 'John', 13) How I can use the sequence with pandas dataframe...
https://stackoverflow.com/questions/73383536/duckdb-efficiently-insert-pandas-dataframe-to-table-with-sequence
python, sql, pandas, dataframe, duckdb
1,660,716,030
se_77884985
stackoverflow
DATA_SCIENCE
SQL-Injection in duckdb-queries on pandas dataframes
SQL-Injection in duckdb-queries on pandas dataframes In a project I am working with duckdb to perform some queries on dataframes. For one of the queries, I have some user-input that I need to add to the query. That is why I am wondering if SQL-Injection is possible in this case. Is there a way a user could harm the ap...
https://stackoverflow.com/questions/77884985/sql-injection-in-duckdb-queries-on-pandas-dataframes
python, pandas, dataframe, sql-injection, duckdb
1,706,258,023
se_78191884
stackoverflow
DATA_SCIENCE
DuckDB pandas pass DataFrame by name easily with IntelliSense support
DuckDB pandas pass DataFrame by name easily with IntelliSense support In DuckDB, we have to directly use the DataFrame variable name as a string in the SQL syntax (as shown here): import pandas as pd import duckdb mydf = pd.DataFrame({'a' : [1, 2, 3]}) print(duckdb.query("SELECT SUM(a) FROM mydf").to_df()) But in VS...
https://stackoverflow.com/questions/78191884/duckdb-pandas-pass-dataframe-by-name-easily-with-intellisense-support
python, pandas, dataframe, visual-studio-code, duckdb
1,710,924,110
se_78840931
stackoverflow
DATA_SCIENCE
How to pass a data frame as a parameter in Duckdb
How to pass a data frame as a parameter in Duckdb Given this data frame: df=pd.DataFrame({'var1':['S1','S2'],'var2':['aba','saa',],'var3':['ia','ma'],'var4':[42,21]}) The following query results in a Parser Error: duckdb.sql(''' drop table if exists dat; create table dat as select * ...
https://stackoverflow.com/questions/78840931/how-to-pass-a-data-frame-as-a-parameter-in-duckdb
python, pandas, dataframe, duckdb
1,722,976,498
se_73628387
stackoverflow
DATA_SCIENCE
DuckDB Group by Pandas Index
DuckDB Group by Pandas Index I have a pandas dataframe with a multiindex. How can I reference the indexes in a duck db query? import duckdb import pandas as pd import numpy as np df = pd.DataFrame({ 'i1': np.arange(0, 100), 'i2': np.arange(0, 100), 'c': np.random.randint(0 , 10, 100) }).set_index(['i1', 'i2']) ...
https://stackoverflow.com/questions/73628387/duckdb-group-by-pandas-index
python, pandas, dataframe, duckdb
1,662,503,791
se_75727685
stackoverflow
DATA_SCIENCE
How do I get a list of table-like objects visible to duckdb in a python session?
How do I get a list of table-like objects visible to duckdb in a python session? I like how duckdb lets me query DataFrames as if they were sql tables: df = pandas.read_parquet("my_data.parquet") con.query("select * from df limit 10").fetch_df() I also like how duckdb has metadata commands like SHOW TABLES;, like a r...
https://stackoverflow.com/questions/75727685/how-do-i-get-a-list-of-table-like-objects-visible-to-duckdb-in-a-python-session
python, pandas, dataframe, duckdb
1,678,748,726
se_78321569
stackoverflow
DATA_SCIENCE
Faster way to convert duckdb results to dataframe that is supported by streamlit?
Faster way to convert duckdb results to dataframe that is supported by streamlit? Not sure if I am using DuckDB properly in my streamlit application. The whole point of using duckdb in my streamlit was to make it speedy and responsive enough. import duckdb import pandas as pd import polars as pl import time conn = du...
https://stackoverflow.com/questions/78321569/faster-way-to-convert-duckdb-results-to-dataframe-that-is-supported-by-streamlit
python, pandas, dataframe, streamlit, duckdb
1,713,031,637
se_75610048
stackoverflow
DATA_SCIENCE
AttributeError: module 'aiobotocore' has no attribute 'AioSession' when reading csv from s3_path using Pandas
AttributeError: module &#39;aiobotocore&#39; has no attribute &#39;AioSession&#39; when reading csv from s3_path using Pandas import pandas as pd df = pd.read_csv(<s3_path>) I've tried running after uninstalling 'aiobotocore'. I've tried this as well: pip install --upgrade pandas pip install --upgrade aiobotocore Bu...
https://stackoverflow.com/questions/75610048/attributeerror-module-aiobotocore-has-no-attribute-aiosession-when-reading
python, pandas, dataframe, ubuntu, amazon-s3
1,677,713,537
se_79819301
stackoverflow
DATA_SCIENCE
vp.list of paths and sizes to sunburst plot
vp.list of paths and sizes to sunburst plot I have the following data format: foo0/bar0/a0/b0/c0 50 foo0/bar0/a0/b1 30 foo1/bar0/a0/b0 10 foo1/bar1 20 foo1/bar2/a0/b0/c0 20 foo1/bar2/a0/b0/c1 30 I'd like to create a sunburst plot out of this. I know that plotly can get me the plot if I give it a dataframe. But I'm a ...
https://stackoverflow.com/questions/79819301/vp-list-of-paths-and-sizes-to-sunburst-plot
python, pandas, plotly
1,763,058,045
se_38088652
stackoverflow
DATA_SCIENCE
Pandas: convert categories to numbers
Pandas: convert categories to numbers Suppose I have a dataframe with countries that goes as: cc | temp US | 37.0 CA | 12.0 US | 35.0 AU | 20.0 I know that there is a pd.get_dummies function to convert the countries to 'one-hot encodings'. However, I wish to convert them to indices instead such that I will get cc_i...
https://stackoverflow.com/questions/38088652/pandas-convert-categories-to-numbers
python, pandas, series, categorical-data, binning
1,467,162,148
se_79882231
stackoverflow
DATA_SCIENCE
I&#39;m tying to combine Excel files from two different years of labor costs. One of the files numerical data is doubling and I can&#39;t find the reason
I&#39;m tying to combine Excel files from two different years of labor costs. One of the files numerical data is doubling and I can&#39;t find the reason I'm using two excel files (each file for the years 2024 and 2025) and combining the files through Pandas. I discovered this issue when checking the sums that my prog...
https://stackoverflow.com/questions/79882231/im-tying-to-combine-excel-files-from-two-different-years-of-labor-costs-one-of
python, excel, pandas, dataframe
1,770,148,384
se_33961028
stackoverflow
DATA_SCIENCE
Remove non-numeric rows in one column with pandas
Remove non-numeric rows in one column with pandas There is a dataframe like the following, and it has one unclean column 'id' which it sholud be numeric column id, name 1, A 2, B 3, C tt, D 4, E 5, F de, G Is there a concise way to remove the rows because tt and de are not numeric values tt,D de,G to make t...
https://stackoverflow.com/questions/33961028/remove-non-numeric-rows-in-one-column-with-pandas
python, pandas
1,448,639,975
se_79885387
stackoverflow
DATA_SCIENCE
Why doesn&#39;t pandas.Series treat strings as iterables?
Why doesn&#39;t pandas.Series treat strings as iterables? From the pandas documentation, while creating a Series, it can take the following input as data: Array-like Iterable Scalar value String is a type of iterable, but when I try to create a Series using a string: s = pd.Series(data= "abcd") print(s) I get a Ser...
https://stackoverflow.com/questions/79885387/why-doesnt-pandas-series-treat-strings-as-iterables
python, pandas, string
1,770,573,351
se_69824730
stackoverflow
DATA_SCIENCE
Check if value in pandas dataframe is within any two values of two other columns in another dataframe
Check if value in pandas dataframe is within any two values of two other columns in another dataframe I have two dataframes of different length. dfSamples (63012375 rows) and dfFixations (200000 rows). dfSamples = pd.DataFrame({'tSample':[4, 6, 8, 10, 12, 14]}) dfFixations = pd.DataFrame({'tStart':[4,12],'tEnd':[8,1...
https://stackoverflow.com/questions/69824730/check-if-value-in-pandas-dataframe-is-within-any-two-values-of-two-other-columns
python, pandas, dataframe, vectorization
1,635,941,968
se_77978057
stackoverflow
DATA_SCIENCE
Turn level of MultiIndex columns into a column with values (unstack columns)
Turn level of MultiIndex columns into a column with values (unstack columns) I have a DraFrame with a MultiIndex in the columns, and I want to turn the first level into its own column. Original df pd.DataFrame( { ('a', 'm1'): [0,1], ('a', 'm2'): [10, 11], ('b', 'm1'): [2,3], ('b', '...
https://stackoverflow.com/questions/77978057/turn-level-of-multiindex-columns-into-a-column-with-values-unstack-columns
python, pandas, dataframe
1,707,678,386
se_41642799
stackoverflow
DATA_SCIENCE
How to overlay data over a &quot;day period&quot; in Pandas for plotting
How to overlay data over a &quot;day period&quot; in Pandas for plotting I have a DataFrame with some (more-sensical) data in the following form: In[67] df Out[67]: latency timestamp 2016-09-15 00:00:00.000000 0.042731 2016-09-15 00:16:24.376901 0.930874 2016...
https://stackoverflow.com/questions/41642799/how-to-overlay-data-over-a-day-period-in-pandas-for-plotting
python, pandas, matplotlib, plot
1,484,338,664
se_51898826
stackoverflow
DATA_SCIENCE
Converting object column in pandas dataframe to datetime
Converting object column in pandas dataframe to datetime I have an object column in a pandas dataframe in the format dd/mm/yyyy, that I want to convert with to_datetime. I tried to convert it to datetime using the below: df['Time stamp'] = pd.to_datetime(df['Time stamp'], format= '%d/%m/%Y') I get the following er...
https://stackoverflow.com/questions/51898826/converting-object-column-in-pandas-dataframe-to-datetime
python, pandas, datetime
1,534,520,486
se_63200530
stackoverflow
DATA_SCIENCE
python/pandas equivalent to dplyr 1.0.0 summarize(across())
python/pandas equivalent to dplyr 1.0.0 summarize(across()) In R, I find the following very useful when dealing with many variables: library(dplyr) dat <- group_by(mtcars, cyl) summarize(dat, across(c('mpg','disp'), sum), across(c('drat','wt','qsec'), mean)) # A tibble: 3 x 5 cyl disp hp drat wt <dbl> <...
https://stackoverflow.com/questions/63200530/python-pandas-equivalent-to-dplyr-1-0-0-summarizeacross
python, r, pandas, dplyr
1,596,240,734
se_69194678
stackoverflow
DATA_SCIENCE
Python: fast aggregation of many observations to daily sum
Python: fast aggregation of many observations to daily sum I have observations with start and end date of the following format: import pandas as pd data = pd.DataFrame({ 'start_date':pd.to_datetime(['2021-01-07','2021-01-04','2021-01-12','2021-01-03']), 'end_date':pd.to_datetime(['2021-01-16','2021-01-12','20...
https://stackoverflow.com/questions/69194678/python-fast-aggregation-of-many-observations-to-daily-sum
python, pandas
1,631,714,669
se_71921047
stackoverflow
DATA_SCIENCE
pd.Series to pd.DataFrame while multiplying each element with each other element
pd.Series to pd.DataFrame while multiplying each element with each other element Assuming I have a vector of the form | a | b | c | d |, e.g. vec = pd.Series([0.3,0.2,0.2,0.3]) What's a quick and elegant way to build a pd.DataFrame of the form: | a*a | a*b | a*c | a*d | | b*a | b*b | b*c | b*d | | c*a | c*b | c*c | c...
https://stackoverflow.com/questions/71921047/pd-series-to-pd-dataframe-while-multiplying-each-element-with-each-other-element
python, pandas, dataframe, math
1,650,352,917
se_67885441
stackoverflow
DATA_SCIENCE
Python Telethon: Scrape and store Telegram messages
Python Telethon: Scrape and store Telegram messages I used to code in R, but have recently switched back to Python. For a research project about hate speech, I like to display and store messages from Telegram channels with telethon in a dataframe. I need to store the data because I want to visualise and analyse it com...
https://stackoverflow.com/questions/67885441/python-telethon-scrape-and-store-telegram-messages
python, pandas, telegram, telethon
1,623,147,521
se_79884111
stackoverflow
DATA_SCIENCE
Query executed with PyMySQL resulting in copies of column names
Query executed with PyMySQL resulting in copies of column names I would like to import some data stored in MySQL DB to Python environment. I used pymysql for the connection. Then I tried to shoot the following query from Python to MySQL. def get_latest_window(resv, start_date): connection = pymysql.connect( ...
https://stackoverflow.com/questions/79884111/query-executed-with-pymysql-resulting-in-copies-of-column-names
python, pandas, pymysql
1,770,365,150
se_74812000
stackoverflow
DATA_SCIENCE
How should I sort and group data based on different variables
How should I sort and group data based on different variables I have data similar to the one below where shows are given a review score. I have also hot-encoded it with values of either 0 or 1 (true or false) based on their listed genres show review score Action & Adventure Anime Features Anime Series British TV S...
https://stackoverflow.com/questions/74812000/how-should-i-sort-and-group-data-based-on-different-variables
python, pandas, one-hot-encoding
1,671,109,535
se_79883151
stackoverflow
DATA_SCIENCE
Extract nested dictionary values into flat data for dataframe
Extract nested dictionary values into flat data for dataframe How do I extract dictionary key values from every level into a dataframe? I used pd.json_normalize but it doesn't suit my needs since it puts the previous keys as prefixes. This is what I tried import pandas as pd myfamily = { "child1": { "name...
https://stackoverflow.com/questions/79883151/extract-nested-dictionary-values-into-flat-data-for-dataframe
python, pandas, dataframe
1,770,250,038
se_79878170
stackoverflow
DATA_SCIENCE
Locate where a map boundary is in the world with my created shapefile
Locate where a map boundary is in the world with my created shapefile I made a shapefile containing the boundaries of all the worlds countries and some of their regions (like the states in the US, Canadian provinces, etc). I've been trying to set a boundary box of my choosing and see if it can tell me exactly what reg...
https://stackoverflow.com/questions/79878170/locate-where-a-map-boundary-is-in-the-world-with-my-created-shapefile
python, pandas, matplotlib, geopandas, shapely
1,769,622,254
se_51007968
stackoverflow
DATA_SCIENCE
How can i write a data frame to a specific partition of a date partitioned BQ table using to_gbq()
How can i write a data frame to a specific partition of a date partitioned BQ table using to_gbq() I have a dataframe which I want to write to date partitioned BQ table. I am using to_gbq() method to do this. I am able to replace or append the existing table but can't write to a specific partition of the table using t...
https://stackoverflow.com/questions/51007968/how-can-i-write-a-data-frame-to-a-specific-partition-of-a-date-partitioned-bq-ta
pandas, google-bigquery
1,529,826,803
se_56933678
stackoverflow
DATA_SCIENCE
Pandas update doesn&#39;t do anything
Pandas update doesn&#39;t do anything I have a dataframe with some information on it. I created another dataframe that is larger and has default values in it. I want to update the default dataframe with the values from the first dataframe. I'm using df.update but nothing is happening. Here is the code: new_df = pd.Da...
https://stackoverflow.com/questions/56933678/pandas-update-doesnt-do-anything
python, pandas
1,562,584,307