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_63070513
stackoverflow
DATA_SCIENCE
Getting Error: "ValueError: 2 is not in range" when working with Pandas
Getting Error: "ValueError: 2 is not in range" when working with Pandas I have got this error when try split my one column to few columns. But it split on just on one or two columns.If you wanna split on 3,4,5 columns it writes: ValueError Traceback (most recent call last) /usr...
https://stackoverflow.com/questions/63070513/getting-error-valueerror-2-is-not-in-range-when-working-with-pandas
python, pandas, numpy, dataframe
1,595,581,926
se_55404141
stackoverflow
DATA_SCIENCE
How to read a CSV file without using external libraries (such as Numpy, Pandas)?
How to read a CSV file without using external libraries (such as Numpy, Pandas)? This is a question that usually appears in interviews. I know how to read csv files using Pandas. However I am struggling to find a way to read files without using external libraries. Does Python come with any module that would help read ...
https://stackoverflow.com/questions/55404141/how-to-read-a-csv-file-without-using-external-libraries-such-as-numpy-pandas
python, excel, pandas, dataframe, csv
1,553,796,078
se_79828200
stackoverflow
DATA_SCIENCE
How to resample timeseries with origin aligned to start of year
How to resample timeseries with origin aligned to start of year Consider the following pandas Series with a DatatimeIndex of daily values (using day-of-year as an example): import pandas as pd dti = pd.date_range("2017-11-02", "2019-05-21", freq="D", inclusive="both") s = pd.Series(dti.dayofyear.astype(float), index=...
https://stackoverflow.com/questions/79828200/how-to-resample-timeseries-with-origin-aligned-to-start-of-year
python, pandas, dataframe, time-series, pandas-resample
1,763,947,121
se_60783326
stackoverflow
DATA_SCIENCE
How can I merge rows so that numbers of one column are greater than or equal to zero and other keys match?
How can I merge rows so that numbers of one column are greater than or equal to zero and other keys match? I am working on a project so that items in different physical areas can be consolidated for maximum area optimization. I have a list of items with different statuses, types and areas, along with a quantity of tha...
https://stackoverflow.com/questions/60783326/how-can-i-merge-rows-so-that-numbers-of-one-column-are-greater-than-or-equal-to
python, pandas, dataframe
1,584,750,820
se_49991227
stackoverflow
DATA_SCIENCE
Pandas & MatPlotLib: Plot a Bar Graph on Existing Scatter Plot or Vice Versa
Pandas & MatPlotLib: Plot a Bar Graph on Existing Scatter Plot or Vice Versa I have a line graph (plotted using plot(x,y) funstion) plotted in a window, then, would it be possible to Plot a bar graph in/on the same window for visual analysis of the data that was plotted?
https://stackoverflow.com/questions/49991227/pandas-matplotlib-plot-a-bar-graph-on-existing-scatter-plot-or-vice-versa
python, pandas, matplotlib
1,524,525,668
se_79825394
stackoverflow
DATA_SCIENCE
How to export or import TOON in pandas?
How to export or import TOON in pandas? I would like to know how to export or import TOON (Token object oriented notation) in pandas.
https://stackoverflow.com/questions/79825394/how-to-export-or-import-toon-in-pandas
python, pandas, dataframe, export
1,763,634,831
se_75211253
stackoverflow
DATA_SCIENCE
Aggregate and Order Different String Columns uniquely on Pandas
Aggregate and Order Different String Columns uniquely on Pandas I am facing a problem to get the unique values of two different columns ordered A-Z and ignoring nan values. I was trying to create an ordered list of unique values, then remove the brackets, but I struggle. Can someone please help me with this? Columns t...
https://stackoverflow.com/questions/75211253/aggregate-and-order-different-string-columns-uniquely-on-pandas
python, pandas, dataframe, sorting, lambda
1,674,485,849
se_57124972
stackoverflow
DATA_SCIENCE
How to fix 'TypeError: cannot convert dictionary update sequence element #0 to a sequence'
How to fix 'TypeError: cannot convert dictionary update sequence element #0 to a sequence' I'm looking at Google's free machine learning crash course and am trying to make a predicting model based on the first part of their course. However, in the input function, where there's a dictionary, I keep getting this...
https://stackoverflow.com/questions/57124972/how-to-fix-typeerror-cannot-convert-dictionary-update-sequence-element-0-to-a
python, pandas, dictionary, tensorflow, regression
1,563,627,643
se_79683477
stackoverflow
DATA_SCIENCE
How to calculate interest based on conditions and add cumulatively to following rows balance and interest
How to calculate interest based on conditions and add cumulatively to following rows balance and interest I am trying to develop an account summary table based on charges and monthly payments. The condition is that whenever a payment is paid over 7 days late (or not at all), it triggers an interest calculation based o...
https://stackoverflow.com/questions/79683477/how-to-calculate-interest-based-on-conditions-and-add-cumulatively-to-following
python, pandas, dataframe
1,751,168,791
se_72377467
stackoverflow
DATA_SCIENCE
How do I use awswrangler to read only the first few N rows of a parquet file stored in S3?
How do I use awswrangler to read only the first few N rows of a parquet file stored in S3? I am trying to use awswrangler to read into a pandas dataframe an arbitrarily-large parquet file stored in S3, but limiting my query to the first N rows due to the file's size (and my poor bandwidth). I cannot see how to do it, ...
https://stackoverflow.com/questions/72377467/how-do-i-use-awswrangler-to-read-only-the-first-few-n-rows-of-a-parquet-file-sto
python, pandas, dataframe, amazon-s3, aws-data-wrangler
1,653,480,904
se_79825662
stackoverflow
DATA_SCIENCE
Pandas converts Excel strings like ‘2004E205’ to scientific notation — how to prevent this
Pandas converts Excel strings like ‘2004E205’ to scientific notation — how to prevent this How can I handle string values that contain patterns like xxxE205 (e.g., 2004E205), which are used as unique codes in my company? I explicitly read the column as a string in pandas, but values containing xxxExxx are still being ...
https://stackoverflow.com/questions/79825662/pandas-converts-excel-strings-like-2004e205-to-scientific-notation-how-to-pr
python, excel, pandas, string, scientific-notation
1,763,651,487
se_36122586
stackoverflow
DATA_SCIENCE
Pandas: can't drop columns: ValueError: labels [<colName>] not contained in axis
Pandas: can&#39;t drop columns: ValueError: labels [&lt;colName&gt;] not contained in axis I have a df created from a simple CSV. When I try to reference columns by their names, to merge into a new df or to drop, I am getting a ValueError: labels [<colName>] not contained in axis I understand that to drop a column...
https://stackoverflow.com/questions/36122586/pandas-cant-drop-columns-valueerror-labels-colname-not-contained-in-axis
python, python-2.7, pandas, dataframe
1,458,530,180
se_70188386
stackoverflow
DATA_SCIENCE
Is pandas sort_values() deterministic in case of ties?
Is pandas sort_values() deterministic in case of ties? I was wondering whether pandas sorting with sort_values() is a deterministic operation in case of ties, i.e. if calling df.sort_values('foo') would always return the same sorting, no matter how often I run it? One example would be df=pd.DataFrame(np.random.randint...
https://stackoverflow.com/questions/70188386/is-pandas-sort-values-deterministic-in-case-of-ties
python, pandas
1,638,378,414
se_33783072
stackoverflow
DATA_SCIENCE
.head() and .tail() with negative indexes on pandas GroupBy object
.head() and .tail() with negative indexes on pandas GroupBy object I'm having trouble with filtering all but the last 1 element in each group of groupby object of pandas.DataFrame: x = pd.DataFrame([['a', 1], ['b', 1], ['a', 2], ['b', 2], ['a', 3], ['b', 3]], columns=['A', 'B']) g = x.groupby('A') ...
https://stackoverflow.com/questions/33783072/head-and-tail-with-negative-indexes-on-pandas-groupby-object
python, pandas, group-by
1,447,858,024
se_62218113
stackoverflow
DATA_SCIENCE
How to perform calculation based on index?
How to perform calculation based on index? Im very new to Python, hopefully someone can help to solve this issue. Im trying to create a calculation in power bi based on my index. The reason for that is because my index resets from 1 to 250 every time one of my columns has a new value. kind of index by category. Index:...
https://stackoverflow.com/questions/62218113/how-to-perform-calculation-based-on-index
python, pandas
1,591,368,560
se_79821366
stackoverflow
DATA_SCIENCE
How to get a true/false without duplicates when comparing two Pandas dataframes?
How to get a true/false without duplicates when comparing two Pandas dataframes? I have one dataframe with sessions - one session, one row, so SID is unique. The session has a doctor name. SID Doctor Patient 1 robby david 2 langdon sara 3 langdon michael I have another dataframe with the SID, and a recor...
https://stackoverflow.com/questions/79821366/how-to-get-a-true-false-without-duplicates-when-comparing-two-pandas-dataframes
python, pandas, dataframe
1,763,285,394
se_63660610
stackoverflow
DATA_SCIENCE
How to perform semi join with multiple columns in pandas?
How to perform semi join with multiple columns in pandas? Let's say I have these two data frames: >>> df1 = pd.DataFrame({'grp':[1,1,2], 'x':[6,4,2], 'y':[7,8,9]}) >>> df1 grp x y 0 1 6 7 1 1 4 8 2 2 2 9 >>> df2 = pd.DataFrame({'grp':[1], 'x':[6], 'z':[3]}) >>> df2 grp x z 0 1 6 3 I figur...
https://stackoverflow.com/questions/63660610/how-to-perform-semi-join-with-multiple-columns-in-pandas
python, pandas, dataframe, semi-join
1,598,811,070
se_78085938
stackoverflow
DATA_SCIENCE
Pandas pd.read_csv() using single quote as quotechar throws SyntaxError: incomplete input
Pandas pd.read_csv() using single quote as quotechar throws SyntaxError: incomplete input I am currently trying to read in a .csv with the following structure: samplecsv = """ 'column A', 'column b', 'column c', 'valueA', 'valueb', 'valuec,d', 'valueA', 'valueb', 'valuecd', 'valueA', 'valueb', 'valuecd', 'valueA'...
https://stackoverflow.com/questions/78085938/pandas-pd-read-csv-using-single-quote-as-quotechar-throws-syntaxerror-incompl
python, pandas, dataframe, csv
1,709,275,152
se_78152837
stackoverflow
DATA_SCIENCE
Why do I get NotImplementedError trying to create a dataframe from a database table?
Why do I get NotImplementedError trying to create a dataframe from a database table? Using Pandas I can't read from an SQLite table: import pandas as pd import sqlite3 as sq with sq.connect("master.db") as con: table = "personal" df = pd.read_sql_table(table, con) Database file and code are in the same direc...
https://stackoverflow.com/questions/78152837/why-do-i-get-notimplementederror-trying-to-create-a-dataframe-from-a-database-ta
python, pandas, sqlite
1,710,324,161
se_77244301
stackoverflow
DATA_SCIENCE
DataFrame splitting rows on multiple conditions into two sets, behaviour unexpected
DataFrame splitting rows on multiple conditions into two sets, behaviour unexpected I'm trying to split my data in two sets (setA and setB) based on the properties and size of the data. Given a dataframe of random data: import pandas as pd import string import random # Create a DataFrame with random data names = [''....
https://stackoverflow.com/questions/77244301/dataframe-splitting-rows-on-multiple-conditions-into-two-sets-behaviour-unexpec
python, pandas, dataframe
1,696,593,842
se_70325819
stackoverflow
DATA_SCIENCE
How to solve BadZipFile: File is not a zip file error in Jupyter Notebook?
How to solve BadZipFile: File is not a zip file error in Jupyter Notebook? I'm trying to read .xlsx files from folders in a specific directory and to write/export them into 4 new .xlsx files, which every new .xlsx will be containing data catalog per year. The script works well when i tried it some months ago but it's ...
https://stackoverflow.com/questions/70325819/how-to-solve-badzipfile-file-is-not-a-zip-file-error-in-jupyter-notebook
python, pandas, openpyxl
1,639,328,922
se_79823495
stackoverflow
DATA_SCIENCE
Problem converting a column to datetime format
Problem converting a column to datetime format I have a data frame and I am trying to convert the time column into a datetime format. The first step I did was: data['time'] = data.time data['time']=pd.to_datetime(data['time'], format='%H:%M:%S.%f') This helped me successfully change the time column to: dtype('\<M8\[n...
https://stackoverflow.com/questions/79823495/problem-converting-a-column-to-datetime-format
python, pandas, datetime, dtype
1,763,477,534
se_79818431
stackoverflow
DATA_SCIENCE
create dataframe from csv in PythonAnywhere
create dataframe from csv in PythonAnywhere I am trying to display the headers of a data frame I created based on a csv file using the PythonAnywhere free version. I keep getting a huge error message and I don't understand what I did wrong. import pandas as pd data=pd.read_csv('Advertising.csv') df=pd.DataFrame(dat...
https://stackoverflow.com/questions/79818431/create-dataframe-from-csv-in-pythonanywhere
python, pandas, dataframe, csv, pythonanywhere
1,763,005,510
se_79822584
stackoverflow
DATA_SCIENCE
problem on the x-axis of the graph, doesn&#39;t render the time
problem on the x-axis of the graph, doesn&#39;t render the time I am working on a dashboard using Shiny for Python and Plotly Express. I am trying to create a Gantt chart (using px.timeline) to visualize the operating periods of different boilers (ON/OFF states). The Goal: I want to display a horizontal bar chart wher...
https://stackoverflow.com/questions/79822584/problem-on-the-x-axis-of-the-graph-doesnt-render-the-time
python, pandas, dataframe, plotly, py-shiny
1,763,399,896
se_79816665
stackoverflow
DATA_SCIENCE
KeyError when trying to access Symbol columns from NASDAQ Other Symbols FTP export
KeyError when trying to access Symbol columns from NASDAQ Other Symbols FTP export I am trying to make a program to get a list of all (or at least almost all) USA listed stocks on all exchanges. I got AI to generate the following program suggestion: import pandas as pd from ftplib import FTP import io def get_nasdaq...
https://stackoverflow.com/questions/79816665/keyerror-when-trying-to-access-symbol-columns-from-nasdaq-other-symbols-ftp-expo
python, pandas, ftp, keyerror, nasdaq-api
1,762,865,965
se_38783027
stackoverflow
DATA_SCIENCE
Jupyter notebook display two pandas tables side by side
Jupyter notebook display two pandas tables side by side I have two pandas dataframes and I would like to display them in Jupyter notebook. Doing something like: display(df1) display(df2) Shows them one below another: I would like to have a second dataframe on the right of the first one. There is a similar ques...
https://stackoverflow.com/questions/38783027/jupyter-notebook-display-two-pandas-tables-side-by-side
pandas, jupyter-notebook
1,470,380,288
se_79822774
stackoverflow
DATA_SCIENCE
How to count appearance of all items in a row on Pandas Dataframe
How to count appearance of all items in a row on Pandas Dataframe II'm currently learning the Pandas library in Python (without AI assistance), and in one of my tasks I needed to count how many times each item appeared in a row of a DataFrame. Here's an example of the CSV I'm using: ip,datetime,method,url,status,respo...
https://stackoverflow.com/questions/79822774/how-to-count-appearance-of-all-items-in-a-row-on-pandas-dataframe
python, pandas
1,763,413,134
se_79821258
stackoverflow
DATA_SCIENCE
set states to indicate on and off with timestamp
set states to indicate on and off with timestamp def prepare_dataframe(df): # Map original CSV column names to internal aliases for easier access df.rename(columns={ 'Bomba Calor - Temperatura de Aire (°C)': 'temp_aire', 'Bomba Calor - Temperatura Entrada (°C)': 'temp_entrada', 'Bomba C...
https://stackoverflow.com/questions/79821258/set-states-to-indicate-on-and-off-with-timestamp
python, pandas, plotly
1,763,262,754
se_79519830
stackoverflow
DATA_SCIENCE
What is the best way to get the last non zero value in a window of N rows?
What is the best way to get the last non zero value in a window of N rows? This is my dataframe: df = pd.DataFrame({ 'a': [0, 0, 1, -1, -1, 0, 0, 0, 0, 0, -1, 0, 0, 1, 0] }) Expected output is creating column b: a b 0 0 0 1 0 0 2 1 0 3 -1 1 4 -1 -1 5 0 -1 6 0 -1 7 0 -1 8 0 0 9 0 0 10 ...
https://stackoverflow.com/questions/79519830/what-is-the-best-way-to-get-the-last-non-zero-value-in-a-window-of-n-rows
python, pandas
1,742,378,647
se_64021420
stackoverflow
DATA_SCIENCE
Pandas read_csv skiprows with conditional statements
Pandas read_csv skiprows with conditional statements I have a bunch of txt files that i need to compile into a single master file. I use read_csv to extract the information inside. There are some rows to drop, and i was wondering if it's possible to use the skiprows feature without specifying the index number of rows ...
https://stackoverflow.com/questions/64021420/pandas-read-csv-skiprows-with-conditional-statements
python, pandas, dataframe, rows
1,600,837,934
se_17335649
stackoverflow
DATA_SCIENCE
How can I specify column names while reading an Excel file using Pandas?
How can I specify column names while reading an Excel file using Pandas? I read an Excel sheet into a Pandas DataFrame this way: import pandas as pd xl = pd.ExcelFile("Path + filename") df = xl.parse("Sheet1") The first cell's value of each column is selected as the column name for the dataFrame, and I want to speci...
https://stackoverflow.com/questions/17335649/how-can-i-specify-column-names-while-reading-an-excel-file-using-pandas
python, excel, pandas
1,372,313,125
se_79774477
stackoverflow
DATA_SCIENCE
Python to copy a sheet from one Excel file to another, sheet names are the same
Python to copy a sheet from one Excel file to another, sheet names are the same Using Python, I am trying to copy the contents of an Excel sheet, to another Excel file, with the same sheet name. The Pandas code to write to the destination sheet seems to overwrite the whole destination file. The destination file has a ...
https://stackoverflow.com/questions/79774477/python-to-copy-a-sheet-from-one-excel-file-to-another-sheet-names-are-the-same
python, excel, pandas, openpyxl
1,758,784,189
se_68613818
stackoverflow
DATA_SCIENCE
Resampling of OHLC data
Resampling of OHLC data I want to convert 1h OHLC data to xh OHLC data. I am using the resample method like it was proposed in similar threads, but it does not lead to the wanted result. The data: open high low close Volume USD date 2021-07-10 21:00:00 132.060 133.350 131....
https://stackoverflow.com/questions/68613818/resampling-of-ohlc-data
python, pandas, ohlc
1,627,846,978
se_79821053
stackoverflow
DATA_SCIENCE
Python, parse nested JSON to make it flat for CSV
Python, parse nested JSON to make it flat for CSV I'm trying to store API output into CSV/db and can not figure out how I can make for those Key in "tierList". One row in my case should be on bin and I need key as a columns in my output. Is it possible to do with pd.JSON_Normalize ? Please direct me to the right lib/t...
https://stackoverflow.com/questions/79821053/python-parse-nested-json-to-make-it-flat-for-csv
python, json, pandas, csv
1,763,233,223
se_79808233
stackoverflow
DATA_SCIENCE
How to use Pandas style objects to format values with a hyperlink based on the index?
How to use Pandas style objects to format values with a hyperlink based on the index? I want to format a Pandas DataFrame with a hyperlink based on the index. import pandas as pd df = (pd.DataFrame([dict(food='bananas', count=33, color='yellow'), dict(food='apples', count=42, color='red'), ...
https://stackoverflow.com/questions/79808233/how-to-use-pandas-style-objects-to-format-values-with-a-hyperlink-based-on-the-i
python, pandas, pandas-styles
1,762,197,330
se_37003100
stackoverflow
DATA_SCIENCE
Pandas groupby for zero values
Pandas groupby for zero values I have data like this in a csv file Symbol Action Year AAPL Buy 2001 AAPL Buy 2001 BAC Sell 2002 BAC Sell 2002 I am able to read it and groupby like this df.groupby(['Symbol','Year']).count() I get Action Symbol Year AAPL 2001 ...
https://stackoverflow.com/questions/37003100/pandas-groupby-for-zero-values
python, pandas, dataframe, group-by
1,462,275,490
se_79819326
stackoverflow
DATA_SCIENCE
No module named &#39;pyspark.sql.metrics&#39; when working with pickle or joblib on Databrick
No module named &#39;pyspark.sql.metrics&#39; when working with pickle or joblib on Databrick I read data from Databricks import pandas as pd import joblib query = 'select * from table a" df = spark.sql(query) df = df.toPandas() df.to_pickle('df.pickle') joblib.dump(df, 'df.joblib') Then I try to read what I saved o...
https://stackoverflow.com/questions/79819326/no-module-named-pyspark-sql-metrics-when-working-with-pickle-or-joblib-on-data
python, pandas, databricks, pickle, joblib
1,763,059,908
se_43483365
stackoverflow
DATA_SCIENCE
Use Pandas groupby() + apply() with arguments
Use Pandas groupby() + apply() with arguments I would like to use df.groupby() in combination with apply() to apply a function to each row per group. I normally use the following code, which usually works (note, that this is without groupby()): df.apply(myFunction, args=(arg1,)) With the groupby() I tried the followi...
https://stackoverflow.com/questions/43483365/use-pandas-groupby-apply-with-arguments
python, pandas, dataframe, group-by, apply
1,492,555,213
se_63303109
stackoverflow
DATA_SCIENCE
Finding all files associated with an id within a folder of images?
Finding all files associated with an id within a folder of images? I'm trying to populate a dataframe based on a class label and images in a folder. I have a folder have over 10,000 images with the following name structure: ['leaflet_10000_1.jpg', 'leaflet_10000_2.jpg', 'leaflet_10001_1.jpg', 'leaflet_10001_2.jpg', 'l...
https://stackoverflow.com/questions/63303109/finding-all-files-associated-with-an-id-within-a-folder-of-images
python, python-3.x, pandas
1,596,807,876
se_79819252
stackoverflow
DATA_SCIENCE
use of melt into a df for long to wide and df.loc
use of melt into a df for long to wide and df.loc i'd like to know if there is another better way of using df_filtered_dates = df.loc[start_date:end_date] or of this way it's good, i'm using for filter dates between the dates i choose from the frontend using flatpickr @reactive.calc def filtered_data(): ...
https://stackoverflow.com/questions/79819252/use-of-melt-into-a-df-for-long-to-wide-and-df-loc
python, pandas, plotly, shiny-reactivity, py-shiny
1,763,055,632
se_76680956
stackoverflow
DATA_SCIENCE
How do I determine the correct encoding of a csv with pd.read_csv?
How do I determine the correct encoding of a csv with pd.read_csv? My file has one value with value which is not recognized by any of the encodings I've tried. The value is assembléia which means assembléia in Portuguese (PT-BR). I followed some tips of this forum, but didn't work. Follow the tips which I've followed...
https://stackoverflow.com/questions/76680956/how-do-i-determine-the-correct-encoding-of-a-csv-with-pd-read-csv
python, pandas, csv, encoding, character-encoding
1,689,261,183
se_79815888
stackoverflow
DATA_SCIENCE
Different epoch time from the same datetime
Different epoch time from the same datetime Here is my code: import pandas as pd import datetime df = pd.DataFrame({'str_date': ['2023091004']}) df['epoch'] = pd.to_datetime(df['str_date'], format='%Y%m%d%H').astype(int) // 10**9 dt = datetime.datetime.strptime(str(2023091004), "%Y%m%d%H") epoch = int(dt.timestamp()...
https://stackoverflow.com/questions/79815888/different-epoch-time-from-the-same-datetime
python, pandas, datetime, epoch
1,762,793,433
se_79817882
stackoverflow
DATA_SCIENCE
How to access specific, indexed elements of a Pandas Dataframe for math?
How to access specific, indexed elements of a Pandas Dataframe for math? What is the right/pythonic way to do math on a few indexed elements in a Pandas Dataframe? I tried a few ways but they seem awkward and confusing: df = pd.DataFrame({'x': [1, 2, 3, 4, 5, 6, 7, 9, ]}) df['y'] = df['x'] / 2 print(df) def printEpr...
https://stackoverflow.com/questions/79817882/how-to-access-specific-indexed-elements-of-a-pandas-dataframe-for-math
python, pandas, dataframe, indexing
1,762,959,631
se_63390090
stackoverflow
DATA_SCIENCE
Python - Splitting positive/negative/neutral/ feedback sentiment score from Vader into separate columns and adding it to data set
Python - Splitting positive/negative/neutral/ feedback sentiment score from Vader into separate columns and adding it to data set I'm trying to determine the sentiment score for customer feedback using VADER in python. The simple code below is running perfectly for individual feedback and returning a dictionary of neg...
https://stackoverflow.com/questions/63390090/python-splitting-positive-negative-neutral-feedback-sentiment-score-from-vade
python, pandas, xlsx, sentiment-analysis, vader
1,597,303,426
se_70431125
stackoverflow
DATA_SCIENCE
How to avoid writing an empty row when I save a multi-header DataFrame into Excel file?
How to avoid writing an empty row when I save a multi-header DataFrame into Excel file? I would like to save a multi-header DataFrame as Excel file. Following is the sample code: import pandas as pd import numpy as np header = pd.MultiIndex.from_product([['location1','location2'], ...
https://stackoverflow.com/questions/70431125/how-to-avoid-writing-an-empty-row-when-i-save-a-multi-header-dataframe-into-exce
python, excel, pandas, dataframe
1,640,065,403
se_79816331
stackoverflow
DATA_SCIENCE
How to store number as a text while exporting from pandas to excel
How to store number as a text while exporting from pandas to excel I have a DataFrame that contains an A/C number column, where some values are longer than 15 digits. When I export the DataFrame to Excel using .to_excel(), Excel automatically converts these long numbers into scientific notation or rounds them off (e.g...
https://stackoverflow.com/questions/79816331/how-to-store-number-as-a-text-while-exporting-from-pandas-to-excel
python, excel, pandas
1,762,845,371
se_79815935
stackoverflow
DATA_SCIENCE
How to assign int input value as column name in pandas
How to assign int input value as column name in pandas I need to take an integer input value, assign it to a variable, and then use that variable as a column name to get data from a pandas DataFrame. Data: 1 10 20 30 2 40 50 60 Steps: Assign input to a variable: Enter value: 1 x =1 Use this variable (x) as a c...
https://stackoverflow.com/questions/79815935/how-to-assign-int-input-value-as-column-name-in-pandas
python, pandas, dataframe, variables
1,762,797,105
se_42263946
stackoverflow
DATA_SCIENCE
How to create a table with clickable hyperlink in pandas &amp; Jupyter Notebook
How to create a table with clickable hyperlink in pandas &amp; Jupyter Notebook print('http://google.com') outputs a clickable url. How do I get clickable URLs for pd.DataFrame(['http://google.com', 'http://duckduckgo.com']) ?
https://stackoverflow.com/questions/42263946/how-to-create-a-table-with-clickable-hyperlink-in-pandas-jupyter-notebook
python, pandas, jupyter-notebook, pandas-styles
1,487,213,435
se_52850667
stackoverflow
DATA_SCIENCE
Pyarrow apply schema when using pandas to_parquet()
Pyarrow apply schema when using pandas to_parquet() I have a very wide data frame (20,000 columns) that is mainly made up of float64 columns in Pandas. I want to cast these columns to float32 and write to Parquet format. I am doing this because the down steam user of these files are small containers with limited memor...
https://stackoverflow.com/questions/52850667/pyarrow-apply-schema-when-using-pandas-to-parquet
python, pandas, pyarrow
1,539,765,754
se_64293690
stackoverflow
DATA_SCIENCE
TypeError: unsupported operand type(s) for /: &#39;str&#39; and &#39;float&#39; when trying to pass interperpolate
TypeError: unsupported operand type(s) for /: &#39;str&#39; and &#39;float&#39; when trying to pass interperpolate Code: cols = ["e_tbhiv_prct", "e_tbhiv_prct_lo", "e_tbhiv_prct_hi", "e_inc_tbhiv_100k", "e_inc_tbhiv_100k_lo", "e_inc_tbhiv_100k_hi", "e_inc_tbhiv_num", "e_inc_tbhiv_num_lo", ...
https://stackoverflow.com/questions/64293690/typeerror-unsupported-operand-types-for-str-and-float-when-trying-to-p
python, pandas, interpolation
1,602,334,691
se_79809778
stackoverflow
DATA_SCIENCE
What is the ideal production-grade infrastructure to deploy a Python FastAPI service for computing option Greeks (e.g., Black–Scholes)?
What is the ideal production-grade infrastructure to deploy a Python FastAPI service for computing option Greeks (e.g., Black–Scholes)? I am building a python service to compute Greek values using python, but I have never worked on python, and I would appreciate advice from the experienced python devs as it would help...
https://stackoverflow.com/questions/79809778/what-is-the-ideal-production-grade-infrastructure-to-deploy-a-python-fastapi-ser
python, pandas, fastapi, trading, best-practices
1,762,330,022
se_19991445
stackoverflow
DATA_SCIENCE
Run an OLS regression with Pandas Data Frame
Run an OLS regression with Pandas Data Frame I have a pandas data frame and I would like to able to predict the values of column A from the values in columns B and C. Here is a toy example: import pandas as pd df = pd.DataFrame({"A": [10,20,30,40,50], "B": [20, 30, 10, 40, 50], ...
https://stackoverflow.com/questions/19991445/run-an-ols-regression-with-pandas-data-frame
python, pandas, scikit-learn, regression, statsmodels
1,384,476,420
se_75846787
stackoverflow
DATA_SCIENCE
last column name is not bold when applying bold font to column names together with hiding index before converting to latex
last column name is not bold when applying bold font to column names together with hiding index before converting to latex I am trying to convert pandas dataframe to latex with column names in bold font at the sam time , with the following code: import pandas as pd df = pd.DataFrame( dict(name=['Raphael', 'Donate...
https://stackoverflow.com/questions/75846787/last-column-name-is-not-bold-when-applying-bold-font-to-column-names-together-wi
python, pandas, dataframe
1,679,821,420
se_50425087
stackoverflow
DATA_SCIENCE
Model Output `to_excel` in Python?
Model Output `to_excel` in Python? Running a MixedLM and want to push the output to Excel or a CSV, see model code and output below: model = smf.mixedlm('y_var ~ gas_prices', dfModel, groups = dfModel['region']) mdf = model.fit() print(mdf.summary()) Mixed Linear Model Regression Re...
https://stackoverflow.com/questions/50425087/model-output-to-excel-in-python
python, python-3.x, pandas, statsmodels
1,526,731,320
se_79812688
stackoverflow
DATA_SCIENCE
After encoding my categorical columns in a pandas dataframe, I was left with too many columns. How can I drop some?
After encoding my categorical columns in a pandas dataframe, I was left with too many columns. How can I drop some? I am using Python with a pandas dataframe, it is a CSV of Steam games, and I have the categorical columns of publishers, developers, categories, genres, and tags, but categories, genres, and tags are the...
https://stackoverflow.com/questions/79812688/after-encoding-my-categorical-columns-in-a-pandas-dataframe-i-was-left-with-too
python, pandas, dataframe, machine-learning, one-hot-encoding
1,762,539,790
se_76684478
stackoverflow
DATA_SCIENCE
Flatten a time series based on its correlation with another time series
Flatten a time series based on its correlation with another time series I would like to flatten a time series column based on its correlation with another column, I am trying a few approach and they are not working... import pandas as pd import numpy as np import random from datetime import datetime, timedelta start_...
https://stackoverflow.com/questions/76684478/flatten-a-time-series-based-on-its-correlation-with-another-time-series
python, pandas, dataframe, time-series
1,689,304,501
se_70295187
stackoverflow
DATA_SCIENCE
How to reset cumulative sum per group when a certain column is 0 in pandas
How to reset cumulative sum per group when a certain column is 0 in pandas I have following dataframe in which I want to make a cumulative sum on a certain column (Value), together with a group by on field Group, but reset that cumulative sum to 0 when a value in another column (Quantity) is 0. Group Quantity Value...
https://stackoverflow.com/questions/70295187/how-to-reset-cumulative-sum-per-group-when-a-certain-column-is-0-in-pandas
python, pandas, dataframe, numpy, group-by
1,639,075,774
se_79811433
stackoverflow
DATA_SCIENCE
Calculate cumulative value based on another column
Calculate cumulative value based on another column Having this kind of pandas dataframe df = pd.DataFrame({ 'ts_diff':[0, 0, 738, 20, 29, 61, 42, 18, 62, 41, 42, 0, 0, 729, 43, 59, 42, 61, 44, 36, 61, 61, 42, 18, 62, 41, 42, 0, 0] }) ts_diff - is duration in milliseconds between events Would like to generate anot...
https://stackoverflow.com/questions/79811433/calculate-cumulative-value-based-on-another-column
python, pandas, dataframe, numpy
1,762,441,003
se_74861745
stackoverflow
DATA_SCIENCE
keyerror: &quot;[&#39;label&#39;] not found in axis&quot;, while using Pandas, even after providing axis=1 and inplace=True
keyerror: &quot;[&#39;label&#39;] not found in axis&quot;, while using Pandas, even after providing axis=1 and inplace=True While trying to drop a column from a dataset, it is showing a keyerror: "['label'] not found in axis". Although I know you have to provide an axis i.e. 1, but even after providing the axis gettin...
https://stackoverflow.com/questions/74861745/keyerror-label-not-found-in-axis-while-using-pandas-even-after-providin
python, pandas, dataframe
1,671,532,626
se_79443482
stackoverflow
DATA_SCIENCE
Find value from row , above and below using If statements in python
Find value from row , above and below using If statements in python import pandas as pd import numpy as np df= pd.read_csv ("file.csv") n = 0 a = 7 # 1st value to find in row1 b = 39 # 2nd value to find in row2 c = 10 # 3rd value to find in row3 d = 38 # 4th value to find in row4 value_1 = 5...
https://stackoverflow.com/questions/79443482/find-value-from-row-above-and-below-using-if-statements-in-python
python, pandas, if-statement
1,739,721,967
se_75210241
stackoverflow
DATA_SCIENCE
How to parse nested XML and extract attributes + tag text both?
How to parse nested XML and extract attributes + tag text both? My XML looks like this: <?xml version="1.0" encoding="UTF-8" ?> <main_heading timestamp="20220113"> <details> <offer id="11" new_id="12"> <level>1&amp;1</level> <typ>Green</typ> <name>Alpha</name> <visits> <...
https://stackoverflow.com/questions/75210241/how-to-parse-nested-xml-and-extract-attributes-tag-text-both
python, pandas, xml, beautifulsoup, xml-parsing
1,674,480,803
se_54588066
stackoverflow
DATA_SCIENCE
Cannot install RAY
Cannot install RAY Ray library from RISE lab (https://rise.cs.berkeley.edu/blog/pandas-on-ray/) I am using Windows 10 Pro, 64-bit and running these scripts from Anaconda prompt. I have tried both pip install ray and pip3 install ray with the same result Collecting ray Could not find a version that satisf...
https://stackoverflow.com/questions/54588066/cannot-install-ray
python, python-3.x, pandas, ray, modin
1,549,612,528
se_69603910
stackoverflow
DATA_SCIENCE
pandas series: why series[-1] = error and series[0] = result
pandas series: why series[-1] = error and series[0] = result Given a series like pd.Series([1,2,3,4]) To get the first value I can do: first = series[0] But to get the last value like last = series[-1] produces an error. I need to do last = series.iloc[-1] I don't understand why. (Why do I don't need first = series.i...
https://stackoverflow.com/questions/69603910/pandas-series-why-series-1-error-and-series0-result
pandas, indexing
1,634,470,438
se_70452647
stackoverflow
DATA_SCIENCE
How to use Python to read Excel files that contain extended fonts? (openpyxl error: Max value is 14)
How to use Python to read Excel files that contain extended fonts? (openpyxl error: Max value is 14) As a learning project for Python, I am attempting to read all Excel files in a directory and extract the names of all the sheets. I have been trying several available Python modules to do this (pandas in this example),...
https://stackoverflow.com/questions/70452647/how-to-use-python-to-read-excel-files-that-contain-extended-fonts-openpyxl-err
python, excel, pandas, openpyxl
1,640,192,797
se_26784313
stackoverflow
DATA_SCIENCE
Converting millions and billion to a number or integer in a Python column
Converting millions and billion to a number or integer in a Python column I have a column that has values like '10 million' and '5 billion' and would like an easy way to just convert that into a numerical value to do some further analysis. I tried powers = {'billion': 10 ** 9, 'million': 10 ** 6} def f(s): try...
https://stackoverflow.com/questions/26784313/converting-millions-and-billion-to-a-number-or-integer-in-a-python-column
python, pandas
1,415,290,935
se_79809062
stackoverflow
DATA_SCIENCE
How to find a common value using if statement
How to find a common value using if statement I am still a beginner in python. I am trying to find a common value with if statement, import pandas as pd df = pd.read_csv("data.csv") for n in range(2, len(df)): if df.loc[n].isin([2]).any(): if df.loc[n-1].isin([1]).any(): print("Yes") n += 1 ...
https://stackoverflow.com/questions/79809062/how-to-find-a-common-value-using-if-statement
python, pandas, dataframe, if-statement, pandas-loc
1,762,268,134
se_79809179
stackoverflow
DATA_SCIENCE
Concatenate Tables Based on Column Information in Python
Concatenate Tables Based on Column Information in Python I have a dataframes pulled from a file. The variable with all these dataframe names is: Data_Tables. These dataframes all have the same columns, and I want to concatenate the dataframes based on the entry for one of the columns, I'll say "fruit" for this example...
https://stackoverflow.com/questions/79809179/concatenate-tables-based-on-column-information-in-python
python, pandas, dataframe, concatenation, iteration
1,762,274,962
se_79807535
stackoverflow
DATA_SCIENCE
Awswrangler: Parquet read into multiple of expected space
Awswrangler: Parquet read into multiple of expected space In a Lambda, I'm using AWS Wrangler to read data out of a date partitioned set of parquets and concatenate them together. I am doing this by calling wr.s3.read_parquet in a loop, compiling the loaded dataframes into a list, and then joining them using pandas.co...
https://stackoverflow.com/questions/79807535/awswrangler-parquet-read-into-multiple-of-expected-space
python, pandas, amazon-s3, aws-lambda, parquet
1,762,144,123
se_75419119
stackoverflow
DATA_SCIENCE
Find names of n largest values in each row of dataframe
Find names of n largest values in each row of dataframe I can find the n largest values in each row of a numpy array (link) but doing so loses the column information which is what I want. Say I have some data: import pandas as pd import numpy as np np.random.seed(42) data = np.random.rand(5,5) data = pd.DataFrame(dat...
https://stackoverflow.com/questions/75419119/find-names-of-n-largest-values-in-each-row-of-dataframe
python, pandas, dataframe
1,676,106,322
se_75438753
stackoverflow
DATA_SCIENCE
Pandas read_html() with table containing html elements
Pandas read_html() with table containing html elements I have the following HTML table: <table> <thead> <th> X1 </th> <th> X2 </th> </thead> <tbody> <tr> <td>Test</td> <td><span style="..."> Test2 </span> </td> </tr> </tbody> </table> that I would want to parse to a dataframe by using pd.read_html...
https://stackoverflow.com/questions/75438753/pandas-read-html-with-table-containing-html-elements
python, html, pandas, parsing, html-parsing
1,676,306,288
se_76255745
stackoverflow
DATA_SCIENCE
re.search is not returning complete match
re.search is not returning complete match I have dataframe with multiple columns of text. In one column with text I try to search for a substring with wildcards in a long string and put the result in a new column. The problem is that I manage to find a result, but the match is not returning the complete string. For ex...
https://stackoverflow.com/questions/76255745/re-search-is-not-returning-complete-match
python, pandas, regex, python-re
1,684,165,203
se_79788108
stackoverflow
DATA_SCIENCE
How do I calculate a relative time delta in Pandas?
How do I calculate a relative time delta in Pandas? I have a column of datetimes and I want to get the difference between values in terms of years, months, etc, instead of timedeltas that only provide days. How do I do this in Pandas? Pandas provides DateOffset for relative deltas, but the docs say "the positional arg...
https://stackoverflow.com/questions/79788108/how-do-i-calculate-a-relative-time-delta-in-pandas
python, pandas, datetime
1,760,198,396
se_58398604
stackoverflow
DATA_SCIENCE
time freezing doesn&#39;t work with pandas timestamps
time freezing doesn&#39;t work with pandas timestamps I've noticed this behaviour since at least 2015 and it hasn't changed since. When freezegun (or pytest-freezegun) is used to freeze time in a test, datetime.datetime.now() returns the frozen value while pd.Timestamp('now') and pd.to_datetime('now') do not. Is there...
https://stackoverflow.com/questions/58398604/time-freezing-doesnt-work-with-pandas-timestamps
python, pandas, freezegun
1,571,155,090
se_26358200
stackoverflow
DATA_SCIENCE
Xticks by pandas plot, rename with the string
Xticks by pandas plot, rename with the string I have this df: df = pd.DataFrame({'A': [1, 2, 3], 'B': [2, 3, 5], 'C': ['name 1', 'name 2', 'name 3']}) A B C 0 1 2 name 1 1 2 3 name 2 2 3 5 name 3 What is it the correct way to plot column A and use column C as xticks? These do not work: df['A'].plo...
https://stackoverflow.com/questions/26358200/xticks-by-pandas-plot-rename-with-the-string
python, pandas, matplotlib, plot, xticks
1,413,281,519
se_23464138
stackoverflow
DATA_SCIENCE
Downloading and accessing data from github python
Downloading and accessing data from github python Hi I'm going through Python for Data analysis and I'd like to analyze the data he goes through in the book. In chapter 9, he uses the data below. However, I'm having a difficult time understanding how to utilize the data in my ipython notebook once I download it to my ...
https://stackoverflow.com/questions/23464138/downloading-and-accessing-data-from-github-python
python, git, pandas
1,399,258,998
se_21291259
stackoverflow
DATA_SCIENCE
Convert floats to ints in Pandas?
Convert floats to ints in Pandas? I've been working with data imported from a CSV. Pandas changed some columns to float, so now the numbers in these columns get displayed as floating points! However, I need them to be displayed as integers or without comma. Is there a way to convert them to integers or not display the...
https://stackoverflow.com/questions/21291259/convert-floats-to-ints-in-pandas
python, pandas, dataframe, floating-point, integer
1,390,416,135
se_62221106
stackoverflow
DATA_SCIENCE
pandas Multi-index DataFrame column level values still exists after selection
pandas Multi-index DataFrame column level values still exists after selection I have a multi-index pd.DataFrame: idx = pd.MultiIndex.from_product([['a', 'b'], [1, 2, 3]]) df = pd.DataFrame(index=[1, 2, 3, 4], columns=idx).fillna(0) and I would like to select the 'a' part of the first level of the columns: dfa = df[['...
https://stackoverflow.com/questions/62221106/pandas-multi-index-dataframe-column-level-values-still-exists-after-selection
python, pandas, dataframe
1,591,378,403
se_28772494
stackoverflow
DATA_SCIENCE
How do you update the levels of a pandas MultiIndex after slicing its DataFrame?
How do you update the levels of a pandas MultiIndex after slicing its DataFrame? I have a Dataframe with a pandas MultiIndex: In [1]: import pandas as pd In [2]: multi_index = pd.MultiIndex.from_product( ...: [['CAN', 'USA'], ['total']], ...: names=['country', 'sex']) In [3]: df = pd.DataFrame({'pop': ...
https://stackoverflow.com/questions/28772494/how-do-you-update-the-levels-of-a-pandas-multiindex-after-slicing-its-dataframe
python, pandas
1,425,064,123
se_79806769
stackoverflow
DATA_SCIENCE
How to extract table from PDF with boxes into pandas dataframe
How to extract table from PDF with boxes into pandas dataframe I have code that detects a table in a PDF that appears after a specific section, and parses the information in the table and copies it into a pandas dataframe. Now, I want to indicate whether a box is checked (or not blank) next to the information parsed f...
https://stackoverflow.com/questions/79806769/how-to-extract-table-from-pdf-with-boxes-into-pandas-dataframe
python, pandas, parsing, pdf, ocr
1,762,024,098
se_47916165
stackoverflow
DATA_SCIENCE
Python2: pandas groupby get proportion of NaN in each group
Python2: pandas groupby get proportion of NaN in each group I have a dataframe with a group column and a values column: df = pd.DataFrame({'group': ['CA', 'WA', 'CO', 'AZ', 'MA'] * 10, 'value': pd.Series(range(5) + [np.nan]).sample(50, replace=True)}) How can I use groupby on the group column to ...
https://stackoverflow.com/questions/47916165/python2-pandas-groupby-get-proportion-of-nan-in-each-group
python, pandas, python-2.7
1,513,815,529
se_79807712
stackoverflow
DATA_SCIENCE
Why does the pivoted dataframe contain information about columns that weren&#39;t included in the pivot?
Why does the pivoted dataframe contain information about columns that weren&#39;t included in the pivot? There is a dataframe with a multiindex columns: import pandas as pd df = pd.DataFrame({ "A": ["foo", "foo", "bar", "bar"], "B": ["small", "large", "large", "small"], "C": [1, 2, 2, 7], "D": [2, 4, ...
https://stackoverflow.com/questions/79807712/why-does-the-pivoted-dataframe-contain-information-about-columns-that-werent-in
python, pandas, dataframe, pivot
1,762,163,714
se_61690295
stackoverflow
DATA_SCIENCE
Python-Pandas convert columns into rows
Python-Pandas convert columns into rows My database from excel has some information by Country for Years. The problem is each year is a different column header. For example: Country Indicator 1950 1951 1952 Australia x 10 27 20 Australia y 7 11 8 Australia ...
https://stackoverflow.com/questions/61690295/python-pandas-convert-columns-into-rows
python, pandas
1,588,984,702
se_36285155
stackoverflow
DATA_SCIENCE
Pandas: Get Dummies
Pandas: Get Dummies I have the following dataframe: amount catcode cid cycle date di feccandid type 0 1000 E1600 N00029285 2014 2014-05-15 D H8TX22107 24K 1 5000 G4600 N00026722 2014 2013-10-22 D H4TX28046 24K 2 4 C2100 N00030676 2014 2014-03-26...
https://stackoverflow.com/questions/36285155/pandas-get-dummies
python, pandas, dummy-variable
1,459,256,736
se_75939533
stackoverflow
DATA_SCIENCE
How can I sum cumulatively values on condition in polars or pandas?
How can I sum cumulatively values on condition in polars or pandas? I have a problem i'm trying to solve using preferably polars but pandas is also fine. Say we have the following dataset (sample): import polars as pl df = pl.from_repr(""" ┌─────────────────────┬───────────┬───────────────────┐ │ date ...
https://stackoverflow.com/questions/75939533/how-can-i-sum-cumulatively-values-on-condition-in-polars-or-pandas
python, pandas, dataframe, python-polars
1,680,698,399
se_79806045
stackoverflow
DATA_SCIENCE
New installation get this: main loop could not convert string &#39;2023-01-02&#39; to float64
New installation get this: main loop could not convert string &#39;2023-01-02&#39; to float64 I have just installed the new Mint 22.2 as my old hard disk with Mint 21 seems to have some issues. I use Eric-IDE to execute my .py script. The script is first downloading stock values from a certain date, and after that it ...
https://stackoverflow.com/questions/79806045/new-installation-get-this-main-loop-could-not-convert-string-2023-01-02-to-fl
python, pandas, matplotlib, string-conversion
1,761,930,508
se_79803236
stackoverflow
DATA_SCIENCE
Pandas DataFrame with a hundred million entries and counting the number of identical characters in strings
Pandas DataFrame with a hundred million entries and counting the number of identical characters in strings I have a pandas DataFrame (df) with two columns (namely Tuple and Set) and approximately 100,000,000 entries. The Tuple column data is a string of exactly 9 characters. The Set column data is an ordinal integer f...
https://stackoverflow.com/questions/79803236/pandas-dataframe-with-a-hundred-million-entries-and-counting-the-number-of-ident
python, pandas, dataframe, bigdata, counter
1,761,682,866
se_54715073
stackoverflow
DATA_SCIENCE
Plotting dataframe columns by similarity in header strings on one graph Python
Plotting dataframe columns by similarity in header strings on one graph Python I have a dataframe that has 2 sets of data both with the same or similar names in their headers/column names. The data looks something like this: Cali_Lower_Population Cali_Upper_Population Cali_Lower_Density Cali_Upper_Density ...
https://stackoverflow.com/questions/54715073/plotting-dataframe-columns-by-similarity-in-header-strings-on-one-graph-python
python, python-3.x, pandas, matplotlib, group-by
1,550,255,014
se_79431335
stackoverflow
DATA_SCIENCE
Memory Usage Continues to Increase When Repeatedly Reading Parquet files
Memory Usage Continues to Increase When Repeatedly Reading Parquet files I'm experiencing an issue where my Python script's memory usage continuously increases during repeated processing of Parquet files using PyArrow—even after explicitly deleting objects and forcing garbage collection. The behavior is similar when I...
https://stackoverflow.com/questions/79431335/memory-usage-continues-to-increase-when-repeatedly-reading-parquet-files
python, pandas, dataframe, python-polars, pyarrow
1,739,308,540
se_79428965
stackoverflow
DATA_SCIENCE
Why is this polars filtering so much slower than my pandas equivalent?
Why is this polars filtering so much slower than my pandas equivalent? I'm trying a function in polars, and it is significantly slower than my pandas equivalent. My pandas function is the following: import pandas as pd import time import numpy as np target_value = 0.5 data = np.random.rand(1000,100) df = pd.DataFrame...
https://stackoverflow.com/questions/79428965/why-is-this-polars-filtering-so-much-slower-than-my-pandas-equivalent
python, pandas, dataframe, performance, python-polars
1,739,252,195
se_50020231
stackoverflow
DATA_SCIENCE
pandas: TypeError: unhashable type: &#39;list&#39;
pandas: TypeError: unhashable type: &#39;list&#39; I have the following df: df = pd.DataFrame( [ [["John Muller"], "person", [8866155845]], [["Innovation Division"], "company", np.nan], [["Carol Sway"], "person", [8866155845]], ], columns=["name", "kind", "phone"], ) # Out: # ...
https://stackoverflow.com/questions/50020231/pandas-typeerror-unhashable-type-list
python, list, pandas, hash, duplicates
1,524,652,985
se_79630693
stackoverflow
DATA_SCIENCE
How to apply a pandas filter if the filter requirement is an element in a list
How to apply a pandas filter if the filter requirement is an element in a list I have a dataframe, and a list of potentially different filters. Is there a way to apply a filter that comes from a list so that the dataframe is filtered accordingly? MRE: In this example, the df is filtered based on the conditions set out...
https://stackoverflow.com/questions/79630693/how-to-apply-a-pandas-filter-if-the-filter-requirement-is-an-element-in-a-list
python, pandas, dataframe, list, filter
1,747,753,332
se_34111620
stackoverflow
DATA_SCIENCE
Pandas, Bar Chart Annotations
Pandas, Bar Chart Annotations How to properly give Annotations to Pandas Bar Charts? I'm following Bar Chart Annotations with Pandas and MPL, but somehow I can't make it into my own code. I've also found the following code from here: def autolabel(rects): # attach some text labels for rect in rects: he...
https://stackoverflow.com/questions/34111620/pandas-bar-chart-annotations
python, pandas, matplotlib, plot, charts
1,449,354,201
se_79805740
stackoverflow
DATA_SCIENCE
How to read mixed data (numbers and strings) from Excel with xlwings without converting 123 → 123.0
How to read mixed data (numbers and strings) from Excel with xlwings without converting 123 → 123.0 I’m using xlwings to read an Excel sheet into a pandas DataFrame with the built-in pd.DataFrame converter. Some of my columns contain mixed data (e.g. IDs or codes like 123, 00123, ABCD). When I read the sheet, xlwings ...
https://stackoverflow.com/questions/79805740/how-to-read-mixed-data-numbers-and-strings-from-excel-with-xlwings-without-con
python, excel, pandas, xlwings
1,761,911,125
se_79731877
stackoverflow
DATA_SCIENCE
Pandas DtypeWarning &quot;Columns have mixed types&quot; for large CSV file (no error with one less line)
Pandas DtypeWarning &quot;Columns have mixed types&quot; for large CSV file (no error with one less line) I am using Pandas (v2.2.3) to read/load a (relatively large) CSV file using read_csv(). The full file has about 500k lines. The function throws a DtypeWarning stating that "Columns have mixed types" and suggests t...
https://stackoverflow.com/questions/79731877/pandas-dtypewarning-columns-have-mixed-types-for-large-csv-file-no-error-with
python, pandas, csv
1,754,903,902
se_79805165
stackoverflow
DATA_SCIENCE
Plotly px.timelines shows 1970 even though print(data.dtypes) confirms correct datetime in shiny
Plotly px.timelines shows 1970 even though print(data.dtypes) confirms correct datetime in shiny I'm building a dashboard in Shiny for Python and I'm stuck on a strange bug. I have a Plotly px.timeline that should display boiler on-times based on a date range from a Flatpickr input. The Problem: No matter what date ra...
https://stackoverflow.com/questions/79805165/plotly-px-timelines-shows-1970-even-though-printdata-dtypes-confirms-correct-d
python, pandas, plotly-express, py-shiny
1,761,853,518
se_79804879
stackoverflow
DATA_SCIENCE
How to fix &quot;AttributeError: &#39;Series&#39; object has no attribute &#39;codes&#39;&quot; using pandas.Categorical
How to fix &quot;AttributeError: &#39;Series&#39; object has no attribute &#39;codes&#39;&quot; using pandas.Categorical I am trying to convert a string that is a categorical data type into a numeric. I found out that I can use pandas.Categorical, unfortunately, accessing the codes attribute give me an error. Here is ...
https://stackoverflow.com/questions/79804879/how-to-fix-attributeerror-series-object-has-no-attribute-codes-using-pand
python, pandas, categorical-data
1,761,834,762
se_40506390
stackoverflow
DATA_SCIENCE
&#39;Series&#39; object has no attribute &#39;colNames&#39; (which is a separate variable)
&#39;Series&#39; object has no attribute &#39;colNames&#39; (which is a separate variable) I need to use a lambda function to do a row by row computation. For example create some dataframe import pandas as pd import numpy as np def myfunc(x, y): return x + y colNames = ['A', 'B'] data = np.array([np.arange(10)]*...
https://stackoverflow.com/questions/40506390/series-object-has-no-attribute-colnames-which-is-a-separate-variable
python, pandas, attributeerror
1,478,692,427
se_77409954
stackoverflow
DATA_SCIENCE
Polars and Pandas DataFrame consume almost same memory. Where is the advantage of Polars?
Polars and Pandas DataFrame consume almost same memory. Where is the advantage of Polars? I wanted to compare memory consumption for same dataset. I read same SQL query with pandas and polars from an Oracle DB. Memory usage results are almost same. and execution time is 2 times faster than polars. I expect polars will...
https://stackoverflow.com/questions/77409954/polars-and-pandas-dataframe-consume-almost-same-memory-where-is-the-advantage-o
python, pandas, dataframe, python-polars
1,698,931,389
se_78609465
stackoverflow
DATA_SCIENCE
Animating Yearly Data from Pandas in GeoPandas with Matplotlib FuncAnimation
Animating Yearly Data from Pandas in GeoPandas with Matplotlib FuncAnimation Using this dataset of % change by state, I have merged it with a cartographic boundary map of US states from the Census department: https://www2.census.gov/geo/tiger/GENZ2018/shp/cb_2018_us_state_500k.zip df.head() Year 2017 2018 ...
https://stackoverflow.com/questions/78609465/animating-yearly-data-from-pandas-in-geopandas-with-matplotlib-funcanimation
python, pandas, matplotlib, geopandas, matplotlib-animation
1,718,134,606
se_63195643
stackoverflow
DATA_SCIENCE
Text cleaning: removing dates from text, where there are
Text cleaning: removing dates from text, where there are I would need to clean some text which may contain a sequence like this: Date Text 2020-06-01 1 giu 2020 - Per farlo hai messo in atto un pia... 2020-06-01 La trappola del Paragone 2020-06-05 5 giu 2020 - sistema Aegis Ashore? N... 2020-06-05 Lewis...
https://stackoverflow.com/questions/63195643/text-cleaning-removing-dates-from-text-where-there-are
python, regex, pandas
1,596,212,739