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_79804439 | stackoverflow | DATA_SCIENCE | How to generate scatter plot of all numeric columns against specific columns in the same dataframe | How to generate scatter plot of all numeric columns against specific columns in the same dataframe
I have a dataframe with a mix of data types (object and numeric). I want to plot a scatter plot for all numeric columns in the dataset against specific columns: col_32, col_69,col_74 and col_80 thereby generating 4 figur... | https://stackoverflow.com/questions/79804439/how-to-generate-scatter-plot-of-all-numeric-columns-against-specific-columns-in | pandas, matplotlib, seaborn, png | 1,761,805,113 |
se_79802076 | stackoverflow | DATA_SCIENCE | Why do I get a SettingWithCopyWarning when using shift and dropna inside a function? | Why do I get a SettingWithCopyWarning when using shift and dropna inside a function?
In general, when I receive this warning
/home/mo/mwe.py:7: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead
I head to the second answ... | https://stackoverflow.com/questions/79802076/why-do-i-get-a-settingwithcopywarning-when-using-shift-and-dropna-inside-a-funct | python, pandas, dataframe, pandas-settingwithcopy-warning | 1,761,584,830 |
se_78120048 | stackoverflow | DATA_SCIENCE | pyarrow Table adds column '__index_level_0__' | pyarrow Table adds column '__index_level_0__'
If I create a pandas df and convert that to a pyarrow Table, I got an additional column 'index_level_0'.
How do I get rid of it?
from pyarrow import Table
import pandas as pd
df_empty = pd.DataFrame(columns=["a", "b", "c",])
df_empty = df_empty.astype(
{"a": "... | https://stackoverflow.com/questions/78120048/pyarrow-table-adds-column-index-level-0 | python, pandas, pyarrow | 1,709,802,673 |
se_79575173 | stackoverflow | DATA_SCIENCE | Pandas converting string into a datetime error when writing to a Delta Lake | Pandas converting string into a datetime error when writing to a Delta Lake
I have a CSV file that I am reading to a Pandas dataframe. I am then writing the dataframe to a Microsoft Delta table in a Fabric Lakehouse. The CSV file has multiple string columns that hold datetimes in the format DD/MM/YYYY HH:MM:SS.
The in... | https://stackoverflow.com/questions/79575173/pandas-converting-string-into-a-datetime-error-when-writing-to-a-delta-lake | python, pandas, datetime, microsoft-fabric, delta-rs | 1,744,720,780 |
se_27306373 | stackoverflow | DATA_SCIENCE | how to stop seaborn visualisation sorting the values on the X axis of a bar chart | how to stop seaborn visualisation sorting the values on the X axis of a bar chart
I have a column in a pandas dataframe called month_name which contains some months of the year.
I have tried feeding this data to seaborn visualisation library as both an object and categorical datatype.
I have also tried sorting the ... | https://stackoverflow.com/questions/27306373/how-to-stop-seaborn-visualisation-sorting-the-values-on-the-x-axis-of-a-bar-char | python, pandas, visualization, seaborn | 1,417,736,903 |
se_42314846 | stackoverflow | DATA_SCIENCE | Python Training dataset | Python Training dataset
I am trying to perform music genre classification. I want to use MFCC as a feature. I am using scikit library for that purpose. Here is my code simply:
> import numpy as np
> import scipy.io.wavfile
> from scikits.talkbox.features import mfcc
> sr1,x1=scipy.io.wavfile.read("filename.wav")
> c... | https://stackoverflow.com/questions/42314846/python-training-dataset | python, pandas, numpy, audio, scipy | 1,487,419,078 |
se_79802909 | stackoverflow | DATA_SCIENCE | Execution of pandas' info in python | Execution of pandas' info in python
I am new to the pandas library in python. When I loaded a file and was printing the output of df.info into the console, the data is getting printed first instead of the text that I have printed.
What is causing this behavior (since it was not async I couldn't understand how it i... | https://stackoverflow.com/questions/79802909/execution-of-pandas-info-in-python | python, pandas | 1,761,660,696 |
se_79802715 | stackoverflow | DATA_SCIENCE | Should I drop duplicates before merging two DataFrames or after the merge? | Should I drop duplicates before merging two DataFrames or after the merge?
I have two DataFrames in pandas: customers and flights. Both contain duplicates on the join key (Loyalty#). I am not sure whether the correct workflow is to remove duplicates before the merge or merge first and then dedupe.
Example expert from ... | https://stackoverflow.com/questions/79802715/should-i-drop-duplicates-before-merging-two-dataframes-or-after-the-merge | python, pandas, dataframe | 1,761,649,673 |
se_77222514 | stackoverflow | DATA_SCIENCE | Append many xlsx sheets to a csv file | Append many xlsx sheets to a csv file
I have an Excel workbook with many sheets, which I would like to add to one big CSV file using Python. I have written the code below, which currently only adds the final sheet's data to the CSV. How do I refactor this so that ALL the sheets in the workbook are being added/appended... | https://stackoverflow.com/questions/77222514/append-many-xlsx-sheets-to-a-csv-file | python, pandas, excel | 1,696,338,157 |
se_79802481 | stackoverflow | DATA_SCIENCE | Output of for loop filling down in dataframe instead of returning corresponding values for each row | Output of for loop filling down in dataframe instead of returning corresponding values for each row
I'm using SpaCy to process a series of sentences and return the five most common words in each sentence. My goal is to store the output of that frequency analysis (using Counter) in a column beside each corresponding se... | https://stackoverflow.com/questions/79802481/output-of-for-loop-filling-down-in-dataframe-instead-of-returning-corresponding | python, pandas, spacy | 1,761,632,755 |
se_79794520 | stackoverflow | DATA_SCIENCE | How to drop duplicate values when merging dataframes | How to drop duplicate values when merging dataframes
I have a DataFrame that I want to merge and drop only duplicates values based on column name and row. For example, key_x and key_y has the
same values in the same row in row 0,3,10,12,15.
My DataFrame
import pandas as pd
df1 = pd.DataFrame({'key': ['A', 'B', 'C', 'A... | https://stackoverflow.com/questions/79794520/how-to-drop-duplicate-values-when-merging-dataframes | python, pandas, dataframe, merge, drop-duplicates | 1,760,914,894 |
se_72371067 | stackoverflow | DATA_SCIENCE | How to loop through each row and see if a condition is met between two columns? | How to loop through each row and see if a condition is met between two columns?
I have 3 columns. I want to update the third column status if the first column a is greater than or equal to column b + 0.50. I've tried this following code but cannot get it to work:
if df['a'] >= (df['b'] + 0.50):
df['status'] = 1
Th... | https://stackoverflow.com/questions/72371067/how-to-loop-through-each-row-and-see-if-a-condition-is-met-between-two-columns | python, pandas | 1,653,442,031 |
se_76331344 | stackoverflow | DATA_SCIENCE | How to merge empty cells in a pivot table using Pandas | How to merge empty cells in a pivot table using Pandas
I have a pivot table like this:
table = pd.pivot_table(
df,
values="D",
index=["A", "B"],
columns=["C"],
aggfunc=np.sum,
margins=True,
margins_name="total",
)
For this pivot table, I've found the subtotal:
# Drop column "total" and sort... | https://stackoverflow.com/questions/76331344/how-to-merge-empty-cells-in-a-pivot-table-using-pandas | python, pandas, pivot-table | 1,685,010,917 |
se_79798995 | stackoverflow | DATA_SCIENCE | How to create a column based on 2 other columns of the dataframe? | How to create a column based on 2 other columns of the dataframe?
I have a kivy app and at some point of the code a pandas dataframe loaded from excel and I managed to create already 2 columns filled with booleans.
I need to create a third columns which content depends on the booleans of the columns created but can't ... | https://stackoverflow.com/questions/79798995/how-to-create-a-column-based-on-2-other-columns-of-the-dataframe | python, pandas, assign | 1,761,324,400 |
se_79757518 | stackoverflow | DATA_SCIENCE | Unable to scrape 2nd table from Fbref.com for players table | Unable to scrape 2nd table from Fbref.com for players table
I would like to scrape the 2nd table in the page seen below from the link - https://fbref.com/en/comps/9/2023-2024/stats/2023-2024-Premier-League-Stats on google collab. But pd.read_html only gives me the first table.
enter image description here
Thank you fo... | https://stackoverflow.com/questions/79757518/unable-to-scrape-2nd-table-from-fbref-com-for-players-table | python, pandas, dataframe, web-scraping | 1,757,158,570 |
se_78080477 | stackoverflow | DATA_SCIENCE | error: metadata-generation-failed Encountered error while generating package metadata | error: metadata-generation-failed Encountered error while generating package metadata
I have win 11, pip 24, py 3.13 version
with vs code i try install pandas or any pack nee weel and i get error , pls see the error
64941a35838675a89f451\.mesonpy-06kzgf2t
Build type: native build
Project name: NumPy
... | https://stackoverflow.com/questions/78080477/error-metadata-generation-failed-encountered-error-while-generating-package-met | python, python-3.x, pandas, pip | 1,709,201,277 |
se_79785937 | stackoverflow | DATA_SCIENCE | Why doesn't Pandas concat do a copy when one of the dataframes is empty? | Why doesn't Pandas concat do a copy when one of the dataframes is empty?
Consider this example:
import pandas as pd
df_part1 = pd.DataFrame()
df_part2 = pd.DataFrame({'A': [1,1], 'B': [3,4]})
df_concat_out = pd.concat([df_part1, df_part2])
print("id(df_part2.values) == id(df_concat_out.values):", id(df_part2.value... | https://stackoverflow.com/questions/79785937/why-doesnt-pandas-concat-do-a-copy-when-one-of-the-dataframes-is-empty | python, pandas, dataframe | 1,759,967,820 |
se_79703771 | stackoverflow | DATA_SCIENCE | Comparing 2 Columns to determine if higher or lower | Comparing 2 Columns to determine if higher or lower
trying to Compare 2 Columns lag2open to MGC=F and return if it is higher and returning it as Higher than 0
using GCClose["Higher than 0"] = [GCClose.columns[1]]>= [GCClose.columns[0]] it always returns True, while the validation column diff doesn't support that idea
... | https://stackoverflow.com/questions/79703771/comparing-2-columns-to-determine-if-higher-or-lower | python, pandas | 1,752,685,141 |
se_41100451 | stackoverflow | DATA_SCIENCE | Load Scraped Table via BS4 into Pandas Dataframe | Load Scraped Table via BS4 into Pandas Dataframe
I'm trying to grab any of the Basic Box Score Stat or Advanced Box Score Stats tables from here
I tried doing something like this:
url = "http://www.basketball-reference.com/boxscores/200112100LAC.html"
page = requests.get(url, headers={'User-Agent': 'Mozilla/5.0 (Mac... | https://stackoverflow.com/questions/41100451/load-scraped-table-via-bs4-into-pandas-dataframe | python, pandas, web-scraping, beautifulsoup, html-parsing | 1,481,544,071 |
se_76213658 | stackoverflow | DATA_SCIENCE | How to scrape other fbref.com table? | How to scrape other fbref.com table?
I am trying to get the player standard stats table from this page (https://fbref.com/en/comps/9/stats/Premier-League-Stats) but when I ask it to get me the tables only the squad standard stats tables are pulled. Is there something I am missing? (my code is below)
import pandas as p... | https://stackoverflow.com/questions/76213658/how-to-scrape-other-fbref-com-table | python, pandas, web-scraping, html-parsing | 1,683,669,878 |
se_69247112 | stackoverflow | DATA_SCIENCE | Create columns in pandas dataframe based on values in a particular column | Create columns in pandas dataframe based on values in a particular column
I have the following pandas dataframe:
Name
Subject
Joe
Maths
Joe
Physics
Alba
Physics
Alba
Biology
Alba
Chemistry
George
Linguistics
I want to convert it into the following:
Name
Subject1
Subject2
Subject3
Joe
Math... | https://stackoverflow.com/questions/69247112/create-columns-in-pandas-dataframe-based-on-values-in-a-particular-column | python, pandas, dataframe, reshape | 1,632,085,955 |
se_62391419 | stackoverflow | DATA_SCIENCE | pandas group by and convert rows into multiple columns | pandas group by and convert rows into multiple columns
data = {'groupId':[1,1,2], 'email':['a1@gmail.com', 'a2@gmail.com', 'a3@gmail.com'],
'type':['office','personal','personal'],'name':['santy','santy','will']}
df = pd.DataFrame(data)
I have a dataframe like this
groupId email type name
1 ... | https://stackoverflow.com/questions/62391419/pandas-group-by-and-convert-rows-into-multiple-columns | python, pandas, group-by, pivot-table | 1,592,234,238 |
se_70074621 | stackoverflow | DATA_SCIENCE | Pandas pivot table for multiple columns at once which has duplicate values | Pandas pivot table for multiple columns at once which has duplicate values
I have a pandas dataframe with the columns name, school and marks
name school marks
tom HBS 55
tom HBS 55
tom HBS 14
mark HBS 28
mark HBS 19
lewis HBS 88
How to transpose and convert into like thi... | https://stackoverflow.com/questions/70074621/pandas-pivot-table-for-multiple-columns-at-once-which-has-duplicate-values | python, pandas, dataframe, group-by, pivot | 1,637,633,832 |
se_70220588 | stackoverflow | DATA_SCIENCE | Pandas long to wide (unmelt or similar?) | Pandas long to wide (unmelt or similar?)
I have a melted, long-format dataframe like this:
name = ["A", "A", "B", "B"]
varA = [1, 2, 1, 2]
varB = [200, 250, 200, 250]
val = [4, 8, 1, 0]
df = pd.DataFrame(
data=zip(name, varA, varB, val), columns=["name", "varA", "varB", "val"]
)
How can I reshape it like this?
... | https://stackoverflow.com/questions/70220588/pandas-long-to-wide-unmelt-or-similar | python, pandas, dataframe, reshape | 1,638,564,988 |
se_73784827 | stackoverflow | DATA_SCIENCE | Unable to scrape 2nd table from Fbref.com | Unable to scrape 2nd table from Fbref.com
I would like to scrape the 2nd table in the page seen below from the link - https://fbref.com/en/comps/82/stats/Indian-Super-League-Stats#all_stats_standard
on google collab.
but pd.read_html("https://fbref.com/en/comps/82/stats/Indian-Super-League-Stats#all_stats_standard") o... | https://stackoverflow.com/questions/73784827/unable-to-scrape-2nd-table-from-fbref-com | python, pandas, dataframe, web-scraping, html-parsing | 1,663,667,674 |
se_73142165 | stackoverflow | DATA_SCIENCE | How to scrape this fbref.com football page? | How to scrape this fbref.com football page?
https://fbref.com/en/partidas/25d5b9bd/Coritiba-Cuiaba-2022Julho25-Serie-A
I wanna scrape the Team Stats, such as Possession and Shots on Target, also whats below like Fouls, Corners...
What I have now is very over complicated code, basically stripping and splitting multiple... | https://stackoverflow.com/questions/73142165/how-to-scrape-this-fbref-com-football-page | python, pandas, web-scraping, beautifulsoup, html-parsing | 1,658,942,413 |
se_77548912 | stackoverflow | DATA_SCIENCE | How to extract hidden table from fbref.com website by id? | How to extract hidden table from fbref.com website by id?
I was trying to gather some data for a data analysis project concerning italian football. Unfortunately I can't extract one specific table from the web page, even though the id is correct.
The code is the following one:
import requests
import pandas as pd
from ... | https://stackoverflow.com/questions/77548912/how-to-extract-hidden-table-from-fbref-com-website-by-id | python, pandas, web-scraping, beautifulsoup, html-parsing | 1,700,933,640 |
se_78475139 | stackoverflow | DATA_SCIENCE | Web scraping 2nd table player stats from fbref.com | Web scraping 2nd table player stats from fbref.com
Was hoping for help here. I'm trying to web scrape this second table of player goal and shot creation stats on FB Ref for the MLS, but my script is bringing in the first table of team statistics instead. Can someone help? Code below.
URL: https://fbref.com/en/comps/22... | https://stackoverflow.com/questions/78475139/web-scraping-2nd-table-player-stats-from-fbref-com | python, pandas, web-scraping, html-parsing | 1,715,642,543 |
se_76911108 | stackoverflow | DATA_SCIENCE | Web scraping a table into a pandas DataFrame from fbref.com | Web scraping a table into a pandas DataFrame from fbref.com
I am attempting to to web scrape all of the player stats for each team in the Argentinian soccer league: https://fbref.com/en/comps/21/stats/Primera-Division-Stats. My issue is that I am scraping all of the team data, and cannot figure out how to get just the... | https://stackoverflow.com/questions/76911108/web-scraping-a-table-into-a-pandas-dataframe-from-fbref-com | python, pandas, web-scraping, beautifulsoup, html-parsing | 1,692,168,364 |
se_76395597 | stackoverflow | DATA_SCIENCE | Beautiful Soup: List Index Out of Range when scraping fbref.com | Beautiful Soup: List Index Out of Range when scraping fbref.com
How do i fix this error (Web Scraping)
import requests
standings_url = "https://fbref.com/en/comps/9/Premier-League-Stats"
data = requests.get(standings_url)
from bs4 import BeautifulSoup
import pandas as pd
import time
soup = BeautifulSoup(data.text)... | https://stackoverflow.com/questions/76395597/beautiful-soup-list-index-out-of-range-when-scraping-fbref-com | python, pandas, web-scraping, beautifulsoup, html-parsing | 1,685,787,591 |
se_73323494 | stackoverflow | DATA_SCIENCE | I have a problem doing web scraping with python in fbref.com | I have a problem doing web scraping with python in fbref.com
This is my first post. I will try to do my best.
I am trying to do web scrapping from fbref but I can't solve one of the errors. I get both that the list is out of range and the 'NoneType' object is not iterable.
I copy the code for someone to help me.
#Crea... | https://stackoverflow.com/questions/73323494/i-have-a-problem-doing-web-scraping-with-python-in-fbref-com | python, pandas, web-scraping, beautifulsoup, html-parsing | 1,660,232,625 |
se_76234088 | stackoverflow | DATA_SCIENCE | Web server responding slow while doing data scraping | Web server responding slow while doing data scraping
I am trying to perform a task that requires me to entrance and exit the player info in this page: https://www.baseball-reference.com/leaders/WAR_bat_career.shtml. In this case, I have to get into the webpage of Barry Bonds, who is ranked the first on the standing, s... | https://stackoverflow.com/questions/76234088/web-server-responding-slow-while-doing-data-scraping | python, pandas, web-scraping, beautifulsoup | 1,683,876,801 |
se_76591392 | stackoverflow | DATA_SCIENCE | Web scraping python and cleaning data up | Web scraping python and cleaning data up
I am trying to scrape the schedule/scores from https://www.baseball-reference.com/leagues/majors/2023-schedule.shtml and save them in a csv file that I can import to google drive. For some reason my parsed_data.csv is only displaying "Date,Away Team,Away Score,Home Team,Home Sc... | https://stackoverflow.com/questions/76591392/web-scraping-python-and-cleaning-data-up | python, pandas, web-scraping, beautifulsoup, html-parsing | 1,688,148,952 |
se_67084364 | stackoverflow | DATA_SCIENCE | Web scrape Sports-Reference with Python Beautiful Soup | Web scrape Sports-Reference with Python Beautiful Soup
I am trying to scrape data from Nick Saban's sports reference page so that I can pull in the list of All-Americans he coached and then his Bowl-Win Loss Percentage.
I am new to Python so this has been a massive struggle. When I inspect the page I see div id = #lea... | https://stackoverflow.com/questions/67084364/web-scrape-sports-reference-with-python-beautiful-soup | python, pandas, web-scraping, beautifulsoup, python-requests | 1,618,363,791 |
se_75297653 | stackoverflow | DATA_SCIENCE | Finding href in "https://www.baseball-reference.com/" webpage using a Python webscraper | Finding href in "https://www.baseball-reference.com/" webpage using a Python webscraper
I would like to webscrape all of the "boxscore" hyperlinks found in the webpage highlighted in "requests.get" below and have it printed onto an excel spreadsheet. However, the program below prints all the text found under... | https://stackoverflow.com/questions/75297653/finding-href-in-https-www-baseball-reference-com-webpage-using-a-python-web | python, pandas, web-scraping, beautifulsoup, html-parsing | 1,675,170,444 |
se_78307096 | stackoverflow | DATA_SCIENCE | Problem: How to scrape dynamically loaded data table in Python? | Problem: How to scrape dynamically loaded data table in Python?
Python novice here. I have been learning how to scrape from various baseball sites (Fangraphs, Statcast, Rotowire). I have had success with a few different methods, but the Park Factors table on Statcast is giving me issues. I have tried using Selenium an... | https://stackoverflow.com/questions/78307096/problem-how-to-scrape-dynamically-loaded-data-table-in-python | python, pandas, selenium-webdriver, web-scraping, html-parsing | 1,712,782,702 |
se_63459947 | stackoverflow | DATA_SCIENCE | How to Parse the MLB Team and Player data using Pandas DataFrame? | How to Parse the MLB Team and Player data using Pandas DataFrame?
I am still learning and could use some help. I would like to parse the starting pitchers and their respective teams.
I would like the data in a Pandas Dataframe but do not know how to parse the data correctly. Any suggestions would be very helpful. Than... | https://stackoverflow.com/questions/63459947/how-to-parse-the-mlb-team-and-player-data-using-pandas-dataframe | python, pandas, dataframe, web-scraping, html-parsing | 1,597,707,554 |
se_79354118 | stackoverflow | DATA_SCIENCE | How can I scrape a table from baseball reference using pandas and beautiful soup? | How can I scrape a table from baseball reference using pandas and beautiful soup?
I am trying to scrape the pitching stats on this url and then save the dataframe to a csv file.
https://www.baseball-reference.com/boxes/ARI/ARI202204070.shtml
My current code is below (Python 3.9.7)
_URL = "https://www.baseball-referen... | https://stackoverflow.com/questions/79354118/how-can-i-scrape-a-table-from-baseball-reference-using-pandas-and-beautiful-soup | python, pandas, web-scraping, beautifulsoup, html-parsing | 1,736,835,100 |
se_73515363 | stackoverflow | DATA_SCIENCE | Scraping and Extracting Sports Reference's NBA Box Score data using Class and ID | Scraping and Extracting Sports Reference's NBA Box Score data using Class and ID
I have recently worked on a scraper for NBA box scores from www.basketball-reference.com and am very new to Beautiful Soup. I have attempted to use Widgets however many are broken and it is not an option.So, I have attempted alternati... | https://stackoverflow.com/questions/73515363/scraping-and-extracting-sports-references-nba-box-score-data-using-class-and-id | python, pandas, web-scraping, beautifulsoup, html-parsing | 1,661,648,965 |
se_79718582 | stackoverflow | DATA_SCIENCE | In pandas, how to write the word "nan" as string with to_excel? | In pandas, how to write the word "nan" as string with to_excel?
I have the reverse problem as described in Prevent pandas from interpreting 'NA' as NaN in a string.
I work with older English text data and want to write the word "nan" (i.e. Modern English 'non(e)') into an Excel file.
I want Excel to show thi... | https://stackoverflow.com/questions/79718582/in-pandas-how-to-write-the-word-nan-as-string-with-to-excel | python, pandas, string, nlp, nan | 1,753,790,921 |
se_60821485 | stackoverflow | DATA_SCIENCE | Sort the dataframe column value based on a priority list in python | Sort the dataframe column value based on a priority list in python
I have a dataframe with two columns as sted below:
Col 1 Col2
A RED
B GREEN
C AMBER
D RED
E GREEN
I want the output dataframe as:
Col1 Col2
A RED
D RED
C ... | https://stackoverflow.com/questions/60821485/sort-the-dataframe-column-value-based-on-a-priority-list-in-python | python, pandas, dataframe | 1,584,997,308 |
se_77889765 | stackoverflow | DATA_SCIENCE | How to sort dataframe by specific data in a column | How to sort dataframe by specific data in a column
So, I am studying pandas and one of the tasks was to sort values of the table by borough and holidays(data in this column is only "Y"(if it is holiday) and "N"(if not). Also I avereged pickups(as task asked), but I wanna show data specifically on "Y".
import pandas as... | https://stackoverflow.com/questions/77889765/how-to-sort-dataframe-by-specific-data-in-a-column | python, pandas, dataframe, sorting | 1,706,319,489 |
se_75767309 | stackoverflow | DATA_SCIENCE | Python Speeding Up a Loop for text comparisons | Python Speeding Up a Loop for text comparisons
I have a loop which is comparing street addresses.
It then uses fuzzy matching to tokenise the addresses and compare the addresses. I have tried this both with fuzzywuzzy and rapidfuzz.
It subsequently returns how close the match is.
The aim is to try and take all my stre... | https://stackoverflow.com/questions/75767309/python-speeding-up-a-loop-for-text-comparisons | python, pandas, loops, fuzzywuzzy, rapidfuzz | 1,679,054,029 |
se_59740344 | stackoverflow | DATA_SCIENCE | How to change the first value in a dataframe that meets a certain condition | How to change the first value in a dataframe that meets a certain condition
I have a dataframe called path and want to change the first value of Segment_code from NaN to 0 where IsPaused is equal to 0. I am attempting to do this using:
path[path['IsPaused']==0].head(1)['Segment_code'] = 0
But I still have
>>> path[... | https://stackoverflow.com/questions/59740344/how-to-change-the-first-value-in-a-dataframe-that-meets-a-certain-condition | python, pandas, numpy, dataframe | 1,579,029,436 |
se_79797838 | stackoverflow | DATA_SCIENCE | Pandas's to_datetime function and datetime format | Pandas's to_datetime function and datetime format
I have a .csv file with two columns (Date and Time). The time zone is "Europe/Paris" with a +02:00 hours shift. The file is structured in 2 parts with two datetime formats.
Date
Time
08-11-25
11:00
08-11-25
11:09
08-11-25
11:20
08-11-25
11:30
08-11-2... | https://stackoverflow.com/questions/79797838/pandass-to-datetime-function-and-datetime-format | python, pandas, datetime, timezone | 1,761,225,069 |
se_79798000 | stackoverflow | DATA_SCIENCE | Combining two dataframes and keeping the average | Combining two dataframes and keeping the average
I'm new to coding, and I'm trying to combine the data from two weather stations into one new dataframe sorted by Datetime. I want this new dataframe to contain the average values of the two original dataframes (e.g. Row 1 1.4 for T, 7.5 for TD etc. How do I do this?
The... | https://stackoverflow.com/questions/79798000/combining-two-dataframes-and-keeping-the-average | python, pandas, dataframe, datetime | 1,761,235,750 |
se_73278972 | stackoverflow | DATA_SCIENCE | Discretize all the columns in a dataframe python | Discretize all the columns in a dataframe python
I have a dataframe where all the columns are continous variables, and I want to discretize them in binnings based on frequency (so the binnings have the same size).
In order to do this I just apply the pd.cut function and iterate through the columns, however I'm getting... | https://stackoverflow.com/questions/73278972/discretize-all-the-columns-in-a-dataframe-python | python, pandas, dataframe | 1,659,966,618 |
se_75689444 | stackoverflow | DATA_SCIENCE | fill values ONLY BETWEEN rows in a pandas DataFrame | fill values ONLY BETWEEN rows in a pandas DataFrame
I am working on a project with some pricing data for second hand cars, due to the nature of the data there are gaps in the dataframe I am working with.
I need to fill the gaps in the columns, but only if they are BETWEEN two values (i.e. there are values both above t... | https://stackoverflow.com/questions/75689444/fill-values-only-between-rows-in-a-pandas-dataframe | python, pandas, dataframe | 1,678,391,808 |
se_79797958 | stackoverflow | DATA_SCIENCE | How do you get specific data in unknown row from a csv file using known data from the same row? | How do you get specific data in unknown row from a csv file using known data from the same row?
import geopy # used to get location
from geopy.geocoders import Nominatim
import pandas as pd
from pyproj import Transformer
def get_user_location(): # user location
geolocator = Nominatim(user_agent="Everywhere") # na... | https://stackoverflow.com/questions/79797958/how-do-you-get-specific-data-in-unknown-row-from-a-csv-file-using-known-data-fro | python, pandas, csv | 1,761,232,289 |
se_25160385 | stackoverflow | DATA_SCIENCE | Change an element in the last row of a DataFrame | Change an element in the last row of a DataFrame
I set up a simple DataFrame in pandas:
a = pandas.DataFrame([[1,2,3], [4,5,6], [7,8,9]], columns=['a','b','c'])
>>> print a
a b c
0 1 2 3
1 4 5 6
2 7 8 9
I would like to be able to alter a single element in the last row of. In pandas==0.13.1 I could use... | https://stackoverflow.com/questions/25160385/change-an-element-in-the-last-row-of-a-dataframe | python, pandas | 1,407,328,005 |
se_73343210 | stackoverflow | DATA_SCIENCE | Python, getting ValueError: No tables found matching pattern | Python, getting ValueError: No tables found matching pattern
this is my code
import pandas as pd
f = open("G:\WNBA\wnba_id.txt", "r")
print(f)
for id in f:
matchid.append(id)
_url_template = "https://www.basketball-reference.com/wnba/boxscores/{}"
for x in matchid:
formatted_url = _url_template.format(x)
... | https://stackoverflow.com/questions/73343210/python-getting-valueerror-no-tables-found-matching-pattern | python, pandas, web-scraping | 1,660,384,182 |
se_36973387 | stackoverflow | DATA_SCIENCE | Accessing first column of pandas value_counts | Accessing first column of pandas value_counts
I'm trying to use value_counts() function from Python's pandas package to find the frequency of items in a column. This works and outputs the following:
57 1811
62 630
71 613
53 217
59 185
68 88
52 70
Name: hospitalized, dtype: int64
... | https://stackoverflow.com/questions/36973387/accessing-first-column-of-pandas-value-counts | python, pandas | 1,462,147,483 |
se_68776819 | stackoverflow | DATA_SCIENCE | group by without making any calculation | group by without making any calculation
I would like to know, if there is a function in which you can group the lines based on a column(like dealer) but without making any account (sum,mean,etc)
Example:
Dealer
city
A
x
B
y
C
z
A
h
A
j
A
f
B
s
Would like to be:
Dealer
city
A
x
h
j... | https://stackoverflow.com/questions/68776819/group-by-without-making-any-calculation | python, pandas, dataframe, group-by | 1,628,878,806 |
se_28766133 | stackoverflow | DATA_SCIENCE | Faster way to read Excel files to pandas dataframe | Faster way to read Excel files to pandas dataframe
I have a 14MB Excel file with five worksheets that I'm reading into a Pandas dataframe, and although the code below works, it takes 9 minutes!
Does anyone have suggestions for speeding it up?
import pandas as pd
def OTT_read(xl,site_name):
df = pd.read_excel(xl... | https://stackoverflow.com/questions/28766133/faster-way-to-read-excel-files-to-pandas-dataframe | python, pandas, import-from-excel | 1,425,043,262 |
se_13411544 | stackoverflow | DATA_SCIENCE | Delete a column from a Pandas DataFrame | Delete a column from a Pandas DataFrame
To delete a column in a DataFrame, I can successfully use:
del df['column_name']
But why can't I use the following?
del df.column_name
Since it is possible to access the Series via df.column_name, I expected this to work. | https://stackoverflow.com/questions/13411544/delete-a-column-from-a-pandas-dataframe | python, pandas, dataframe, del | 1,353,047,200 |
se_43590153 | stackoverflow | DATA_SCIENCE | HTTP Error 403: Forbidden when reading HTML | HTTP Error 403: Forbidden when reading HTML
I would like to read the following html"
import pandas as pd
daily_info=pd.read_html('https://www.investing.com/earnings-calendar/',flavor='html5lib')
print(daily_info)
Unfortunately this error appears:
urllib.error.HTTPError: HTTP Error 403: Forbidden
Is t... | https://stackoverflow.com/questions/43590153/http-error-403-forbidden-when-reading-html | python, pandas, https | 1,493,042,411 |
se_79795855 | stackoverflow | DATA_SCIENCE | pandas crosstab with string as second parameter | pandas crosstab with string as second parameter
Is this code, which works, supposed to work?
import pandas as pd
from palmerpenguins import load_penguins
penguins = load_penguins()
pd.crosstab(penguins.species, "count")
species
count
Adelie
152
Chinstrap
68
Gentoo
124
Looking at the documentation for pd... | https://stackoverflow.com/questions/79795855/pandas-crosstab-with-string-as-second-parameter | python, pandas | 1,761,052,209 |
se_79796094 | stackoverflow | DATA_SCIENCE | Creating a new pandas dataframe from shape | Creating a new pandas dataframe from shape
I have information on total number of rows and number of columns for a new pandas dataframe
import pandas as pd
nRow = 10
nCol = 4
Based on this information I want to create a new dataframe where each element will be filled by 1
Is there any direct method available with pand... | https://stackoverflow.com/questions/79796094/creating-a-new-pandas-dataframe-from-shape | python, pandas | 1,761,068,027 |
se_79792272 | stackoverflow | DATA_SCIENCE | Error due to single-level dataframe merge with multi-level indexed dataframe | Error due to single-level dataframe merge with multi-level indexed dataframe
# Read lookup file which only contains 5 columns.
df_lookup = pd.read_excel(
os.path.join(path, 'lookup.xlsx'),
index_col=[0, 1, 2, 3, 4])
# sample df_lookup
# |A |B |C |D |E |
# |--|--|--|--|--|
# |a1|b1|c1|d1|e1|
# Read data file
... | https://stackoverflow.com/questions/79792272/error-due-to-single-level-dataframe-merge-with-multi-level-indexed-dataframe | python, pandas, dataframe, merge | 1,760,624,966 |
se_73823564 | stackoverflow | DATA_SCIENCE | How to merge 2 cells in a pandas dataframe | How to merge 2 cells in a pandas dataframe
I have a table like:
Student id
Course id
Marks
103
201
67
103
203
67
103
204
89
I want to add another row at the bottom like the following where the "Total Marks" text spans over two columns ("Student id" & "Course id"):
Can anyone guide? | https://stackoverflow.com/questions/73823564/how-to-merge-2-cells-in-a-pandas-dataframe | python, html, pandas, dataframe, datatables | 1,663,912,858 |
se_76364135 | stackoverflow | DATA_SCIENCE | How can I merge two data frames that have different numbers of column levels? | How can I merge two data frames that have different numbers of column levels?
I am trying to pivot a data frame and merge. Here is my code:
pivotdf = pd.pivot_table(df, values = ["col5",'col6'], index=['date'], columns = 'Sector')
df = pd.merge(df, pivotdf , on=["date"], how="left", suffixes=["", "_bySector_pivot"])
... | https://stackoverflow.com/questions/76364135/how-can-i-merge-two-data-frames-that-have-different-numbers-of-column-levels | python, pandas | 1,685,444,484 |
se_33396598 | stackoverflow | DATA_SCIENCE | Memory leak issue with pandas | Memory leak issue with pandas
I have a "memory leak" issue with pandas Dataframe. Apparently this is a know issue: Memory leak using pandas dataframe
The tricks used in the answer (use the gc.collect to manually collect garbage and free memory), works but is quite slow.
My problem is that I need to run this loop at 50... | https://stackoverflow.com/questions/33396598/memory-leak-issue-with-pandas | python, python-2.7, pandas, memory-leaks, garbage-collection | 1,446,050,135 |
se_79795928 | stackoverflow | DATA_SCIENCE | pandas.read_csv uses only utf-8 encoding for django file upload | pandas.read_csv uses only utf-8 encoding for django file upload
I'm testing django using file uploads. Was facing a strange issue, when despide which encoding I choose, I'm always getting same error message that pandas is trying to decode with UTF-8
pd.read_csv(file, encoding="cp1257")
getting
*** UnicodeDecodeError:... | https://stackoverflow.com/questions/79795928/pandas-read-csv-uses-only-utf-8-encoding-for-django-file-upload | python, pandas, csv, encoding, encode | 1,761,056,962 |
se_56102886 | stackoverflow | DATA_SCIENCE | Get Date of Monday of specific numbered week of year in Pandas | Get Date of Monday of specific numbered week of year in Pandas
I have a dataframe:
df = pd.DataFrame({'id': [1,2,3,4,5],
'week': [201613, 201714, 201715, 201716, 201717]})
which looks like:
id week
0 1 201613
1 2 201714
2 3 201715
3 4 201716
4 5 201717
The week column is telling ... | https://stackoverflow.com/questions/56102886/get-date-of-monday-of-specific-numbered-week-of-year-in-pandas | python, pandas, dataframe, datetime | 1,557,690,499 |
se_71641666 | stackoverflow | DATA_SCIENCE | Hyperlink in Streamlit dataframe | Hyperlink in Streamlit dataframe
I am attempting to display a clickable hyperlink inside a dataframe containing filtered results on Streamlit. This is my code so far:
import pandas as pd
import streamlit as st
import openpyxl
import numpy as np
from IPython.core.display import display, HTML
df = pd.read_excel(
io=... | https://stackoverflow.com/questions/71641666/hyperlink-in-streamlit-dataframe | python, pandas, hyperlink, streamlit | 1,648,432,447 |
se_49801060 | stackoverflow | DATA_SCIENCE | Skipping range of rows after header through pandas.read_excel | Skipping range of rows after header through pandas.read_excel
I know the argument usecols in pandas.read_excel() allows you to select specific columns.
Say, I read an Excel file in with pandas.read_excel(). My excel spreadsheet has 1161 rows. I want to keep the 1st row (with index 0), and skip rows 2:337. Seems like t... | https://stackoverflow.com/questions/49801060/skipping-range-of-rows-after-header-through-pandas-read-excel | python, excel, pandas, dataframe, file-io | 1,523,548,641 |
se_25447700 | stackoverflow | DATA_SCIENCE | Annotate bars with values on Pandas bar plots | Annotate bars with values on Pandas bar plots
I was looking for a way to annotate my bars in a Pandas bar plot with the rounded numerical values from my DataFrame.
>>> df=pd.DataFrame({'A':np.random.rand(2),'B':np.random.rand(2)},index=['value1','value2'] )
>>> df
A B
value1 0.440... | https://stackoverflow.com/questions/25447700/annotate-bars-with-values-on-pandas-bar-plots | python, matplotlib, plot, pandas, dataframe | 1,408,712,497 |
se_46207530 | stackoverflow | DATA_SCIENCE | Filtering pandas dataframe with multiple Boolean columns | Filtering pandas dataframe with multiple Boolean columns
I am trying to filter a df using several Boolean variables that are a part of the df, but have been unable to do so.
Sample data:
A | B | C | D
John Doe | 45 | True | False
Jane Smith | 32 | False | False
Alan Holmes | 55 | False | True
Eric Lamar | 29 | True... | https://stackoverflow.com/questions/46207530/filtering-pandas-dataframe-with-multiple-boolean-columns | python, pandas, numpy, dataframe, boolean | 1,505,340,400 |
se_79779335 | stackoverflow | DATA_SCIENCE | How to make index into exponential notation? | How to make index into exponential notation?
I've tried to put in the NumPy scientific notation function in different places but that didn't work, other than that I haven't been able to find anything that works
def optimal_resistor(name="",R_min=0,R_max=0,no_R=0,V_in=0,V_min=0,V_max=0,C=0):
si=np.format_float_sci... | https://stackoverflow.com/questions/79779335/how-to-make-index-into-exponential-notation | python, pandas, dataframe, numpy | 1,759,250,354 |
se_51607400 | stackoverflow | DATA_SCIENCE | How to extract first 8 characters from a string in pandas | How to extract first 8 characters from a string in pandas
I have column in a dataframe and i am trying to extract 8 digits from a string. How can I do it
Input
Shipment ID
20180504-S-20000
20180514-S-20537
20180514-S-20541
20180514-S-20644
20180514-S-20644
20180516-S-20009
20180516-S-20009
20180516-S-20009
2018... | https://stackoverflow.com/questions/51607400/how-to-extract-first-8-characters-from-a-string-in-pandas | python, pandas, substring | 1,533,020,953 |
se_69535331 | stackoverflow | DATA_SCIENCE | How to compare 2 dataframes in python unittest using assert methods | How to compare 2 dataframes in python unittest using assert methods
I'm writing unittest for a method that returns a dataframe, but, while testing the output using:
self.asserEquals(mock_df, result)
I'm getting ValueError:
ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any(... | https://stackoverflow.com/questions/69535331/how-to-compare-2-dataframes-in-python-unittest-using-assert-methods | python, pandas, unit-testing, python-unittest, assert | 1,634,015,342 |
se_58397414 | stackoverflow | DATA_SCIENCE | Error when reading HDF files in Python 3.7 with Pandas.read_hdf function | Error when reading HDF files in Python 3.7 with Pandas.read_hdf function
Previously, I have saved multi columns of dataset into one HDF file. The procedure can be outlined as follows:
import pandas as pd
from pandas import HDFStore, DataFrame
from pandas import read_hdf
hdf = HDFStore("FILE.h5")
feature = ['var1','v... | https://stackoverflow.com/questions/58397414/error-when-reading-hdf-files-in-python-3-7-with-pandas-read-hdf-function | python, python-3.x, pandas, dataframe, hdf5 | 1,571,151,046 |
se_79794345 | stackoverflow | DATA_SCIENCE | pywebview: error maximum recursion depth exceeded before pressing button when passing pandas/model objects in js_api | pywebview: error maximum recursion depth exceeded before pressing button when passing pandas/model objects in js_api
I’m embedding a small UI with pywebview and want Python to JS live updates. I created a GPSSpoofingDetector class that loads a pickled sklearn model and a pandas test CSV. I want a JavaScript “Start” bu... | https://stackoverflow.com/questions/79794345/pywebview-error-maximum-recursion-depth-exceeded-before-pressing-button-when-pa | python, pandas, dataframe, serialization, pywebview | 1,760,886,866 |
se_20375561 | stackoverflow | DATA_SCIENCE | Joining pandas DataFrames by Column names | Joining pandas DataFrames by Column names
I have two DataFrames with the following column names:
frame_1:
event_id, date, time, county_ID
frame_2:
countyid, state
I would like to get a DataFrame with the following columns by left-joining on county_ID = countyid:
joined_dataframe:
event_id, date, time, county, state
... | https://stackoverflow.com/questions/20375561/joining-pandas-dataframes-by-column-names | python, pandas, dataframe, join, pandas-merge | 1,386,160,548 |
se_79746894 | stackoverflow | DATA_SCIENCE | Illegal instruction (core dumped) when running Streamlit app on Raspberry Pi 4 | Illegal instruction (core dumped) when running Streamlit app on Raspberry Pi 4
I’m trying to run a small Streamlit app on my Raspberry Pi 4.
For testing, I made a small version with just core functionality:
# main.py
import pandas as pd
import streamlit as st
def main():
st.title("My Streamlit App")
st.write(... | https://stackoverflow.com/questions/79746894/illegal-instruction-core-dumped-when-running-streamlit-app-on-raspberry-pi-4 | python, pandas, raspberry-pi, streamlit | 1,756,214,967 |
se_79793858 | stackoverflow | DATA_SCIENCE | Calculating MultiIndex intersection to a given tolerance in an efficient way | Calculating MultiIndex intersection to a given tolerance in an efficient way
I have two DataFrames, data1 and data2, with 3-level multiindices. The first two levels are floats, and correspond to spatial coordinates (say longitude and latitude). The third level, time, is based on pandas Period objects.
I want to select... | https://stackoverflow.com/questions/79793858/calculating-multiindex-intersection-to-a-given-tolerance-in-an-efficient-way | python, pandas, numpy, indexing, multi-index | 1,760,805,447 |
se_79793878 | stackoverflow | DATA_SCIENCE | Combining Identically Indexed and Column Dataframes into 3d Dataframe | Combining Identically Indexed and Column Dataframes into 3d Dataframe
I have 3 2D DataFrames, all with identical indexes (datetime range) and column names, but different data for these labels. I would like to combine these three 2D dataframes into 1 3D DataFrame with an additional index.
Brief example, suppose I have ... | https://stackoverflow.com/questions/79793878/combining-identically-indexed-and-column-dataframes-into-3d-dataframe | python, pandas, dataframe, numpy | 1,760,807,652 |
se_79793610 | stackoverflow | DATA_SCIENCE | Calculating mean for a column of arrays in pandas | Calculating mean for a column of arrays in pandas
I have below pandas dataframe
import pandas as pd
import numpy as np
dat = pd.DataFrame({
'A': [1,2,3],
'B': [[[np.nan, 0.0, 0.0, 0.0, 0.0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 1]],
[[0.32894736842105265, 0.0394736842105263... | https://stackoverflow.com/questions/79793610/calculating-mean-for-a-column-of-arrays-in-pandas | python, pandas | 1,760,770,268 |
se_79793379 | stackoverflow | DATA_SCIENCE | "UserWarning: No artists with labels found to put in legend" Error when trying to create a legend with labels from dataset | "UserWarning: No artists with labels found to put in legend" Error when trying to create a legend with labels from dataset
I can't get legend labels to show up when I use 'CONDITION' (a longer string) as my x data and hue, however when I use CONDITION_N (a shorter string) as the hue then it appears. Why?
War... | https://stackoverflow.com/questions/79793379/userwarning-no-artists-with-labels-found-to-put-in-legend-error-when-trying-t | python, pandas, matplotlib, seaborn, legend | 1,760,728,053 |
se_44781633 | stackoverflow | DATA_SCIENCE | Join pandas dataframes based on column values | Join pandas dataframes based on column values
I'm quite new to pandas dataframes, and I'm experiencing some troubles joining two tables.
The first df has just 3 columns:
DF1:
item_id position document_id
336 1 10
337 2 10
338 3 10
1001 1 11
1002 ... | https://stackoverflow.com/questions/44781633/join-pandas-dataframes-based-on-column-values | python, pandas, dataframe, join, pandas-merge | 1,498,570,301 |
se_45035929 | stackoverflow | DATA_SCIENCE | Creating new pandas dataframe from certain columns of existing dataframe | Creating new pandas dataframe from certain columns of existing dataframe
I have read a csv file into a pandas dataframe and want to do some simple manipulations on the dataframe. I can not figure out how to create a new dataframe based on selected columns from my original dataframe. My attempt:
names = ['A','B','C','D... | https://stackoverflow.com/questions/45035929/creating-new-pandas-dataframe-from-certain-columns-of-existing-dataframe | python, pandas, dataframe, select, indexing | 1,499,779,630 |
se_79792470 | stackoverflow | DATA_SCIENCE | How can I use wildcard paths from a Pandas dataframe as required rule inputs and outputs in Snakemake? | How can I use wildcard paths from a Pandas dataframe as required rule inputs and outputs in Snakemake?
I have a Snakemake pipeline (https://github.com/V-Varga/SPOT-BGC/tree/main), where I generate input and output file names for various intermediate steps using wildcards that refer back to file and file path names in ... | https://stackoverflow.com/questions/79792470/how-can-i-use-wildcard-paths-from-a-pandas-dataframe-as-required-rule-inputs-and | python, pandas, wildcard, bioinformatics, snakemake | 1,760,640,150 |
se_39089693 | stackoverflow | DATA_SCIENCE | Rolling Regression Estimation in Python dataframe | Rolling Regression Estimation in Python dataframe
I have a dataframe like this:
Date Y X1 X2 X3
22 2004-05-12 9.348158e-09 0.000081 0.000028 0.000036
23 2004-05-13 9.285989e-09 0.000073 0.000081 0.000097
24 2004-05-14 9.732308e-09 0.000085 0.000... | https://stackoverflow.com/questions/39089693/rolling-regression-estimation-in-python-dataframe | python, pandas, dataframe | 1,471,905,069 |
se_79791271 | stackoverflow | DATA_SCIENCE | How to control the zorder values on superimposed bars in a histogram plot in matplotlib | How to control the zorder values on superimposed bars in a histogram plot in matplotlib
I have a list of three dataframes, each of them having four columns of interest. I want to create a figure with four subplots (one for each column). In each subplot, first, I want to create a superimposed histogram of three datafra... | https://stackoverflow.com/questions/79791271/how-to-control-the-zorder-values-on-superimposed-bars-in-a-histogram-plot-in-mat | python, pandas, dataframe, matplotlib, histogram | 1,760,538,174 |
se_66100765 | stackoverflow | DATA_SCIENCE | pandas ValueError: Cannot setitem on a Categorical with a new category, set the categories first | pandas ValueError: Cannot setitem on a Categorical with a new category, set the categories first
Now, I am changing the information inside DataFrame by replacing Yes with 1 and No with 0. Previously, my code worked fine and now I made some changes due to a memory problem.
Previous code "Got Traceback Error mentioned b... | https://stackoverflow.com/questions/66100765/pandas-valueerror-cannot-setitem-on-a-categorical-with-a-new-category-set-the | python, pandas, dataframe | 1,612,783,768 |
se_24745879 | stackoverflow | DATA_SCIENCE | how to apply preprocessing methods on several columns at one time in sklearn | how to apply preprocessing methods on several columns at one time in sklearn
My question is I have so many columns in my pandas data frame and I am trying to apply the sklearn preprocessing using dataframe mapper from sklearn-pandas library such as
mapper= DataFrameMapper([
('gender',sklearn.preprocessing.LabelB... | https://stackoverflow.com/questions/24745879/how-to-apply-preprocessing-methods-on-several-columns-at-one-time-in-sklearn | python, pandas, scikit-learn, sklearn-pandas | 1,405,371,577 |
se_79790365 | stackoverflow | DATA_SCIENCE | Index in to two specific dates on Pandas dataframe | Index in to two specific dates on Pandas dataframe
I have a pandas dataframe where the index is datetime. I learned that I can index in to a specific date using this code:
selected_date_df = df.loc['yyyy-mm-dd']
I can also find data between two dates with this code:
date_range_df = df.loc['yyyy-mm-dd':'yyyy-mm-dd']
... | https://stackoverflow.com/questions/79790365/index-in-to-two-specific-dates-on-pandas-dataframe | python, pandas | 1,760,456,834 |
se_48856595 | stackoverflow | DATA_SCIENCE | Concatenate encoded columns to original data frame using Scikit-learn and Pandas | Concatenate encoded columns to original data frame using Scikit-learn and Pandas
I am trying to encode all the textual data in a .csv file to numeric using Python's Scikit-learn. I am using LabelEncoder and OneHotEncoder on the columns which are of datatype object. I am wondering how to concatenate the new encoded col... | https://stackoverflow.com/questions/48856595/concatenate-encoded-columns-to-original-data-frame-using-scikit-learn-and-pandas | python, pandas, scikit-learn, one-hot-encoding | 1,518,988,146 |
se_62416223 | stackoverflow | DATA_SCIENCE | How to select only few columns in scikit learn column selector pipeline? | How to select only few columns in scikit learn column selector pipeline?
I was reading the scikitlearn tutorial about column transformer. The given example (https://scikit-learn.org/stable/modules/generated/sklearn.compose.make_column_selector.html#sklearn.compose.make_column_selector) works, but when I tried to selec... | https://stackoverflow.com/questions/62416223/how-to-select-only-few-columns-in-scikit-learn-column-selector-pipeline | python, pandas, scikit-learn | 1,592,335,847 |
se_79170754 | stackoverflow | DATA_SCIENCE | Unnesting a pandas json column and keeping an "id" column | Unnesting a pandas json column and keeping an "id" column
I am working on some nested NoSQL data. I would like to unnest it using json_normalize but keep the "id de transação" column so I could merge the resulting dataframe into other dataframes.
import pandas as pd
import json
data = {
"id de transação... | https://stackoverflow.com/questions/79170754/unnesting-a-pandas-json-column-and-keeping-an-id-column | python, pandas, json-normalize | 1,731,081,658 |
se_72175241 | stackoverflow | DATA_SCIENCE | Python Adding values of leaves to nodes | Python Adding values of leaves to nodes
I'm working with the following dataframe:
ID Value
01.1 0.0
01.1.1 0.0
01.1.1.01 0.0
01.1.1.01.001 27508.42
01.1.1.01.002 24170.31
01.1.1.02 25861.82
01.1.1.04 0.0
01.1.1.04.001 0.0
01.1... | https://stackoverflow.com/questions/72175241/python-adding-values-of-leaves-to-nodes | python, pandas, dataframe, group-by | 1,652,113,470 |
se_72188059 | stackoverflow | DATA_SCIENCE | Extracting City and State from a column in CSV using python | Extracting City and State from a column in CSV using python
917 1st St, Dallas, TX 75001
682 Chestnut St, Boston, MA 02215
669 Spruce St, Los Angeles, CA 90001
669 Spruce St, Los Angeles, CA 90001
so, i'm trying to extract the city and state from the given data...
def get_city_state(address):
asplit = address.spl... | https://stackoverflow.com/questions/72188059/extracting-city-and-state-from-a-column-in-csv-using-python | python, pandas, csv, data-science | 1,652,192,398 |
se_72189191 | stackoverflow | DATA_SCIENCE | Convert Nested DateTime json to Pandas DataFrame | Convert Nested DateTime json to Pandas DataFrame
The problem here is different than those defined in the questions here, here, and here. Specifically, the transformation and form of the output I want is different than any specified in those questions, and I also want a DateTime index. These differences cause the answe... | https://stackoverflow.com/questions/72189191/convert-nested-datetime-json-to-pandas-dataframe | python, pandas, json-normalize | 1,652,196,770 |
se_72189297 | stackoverflow | DATA_SCIENCE | how to transform numerical to categorical (binary) variable and why do nan values reappear after filling in with zeros? | how to transform numerical to categorical (binary) variable and why do nan values reappear after filling in with zeros?
I need to create a categorical (binary) variable from an existing numerical variable that has missing values. After filling in with zeros, nan values re-appear. This is causing issues as later I woul... | https://stackoverflow.com/questions/72189297/how-to-transform-numerical-to-categorical-binary-variable-and-why-do-nan-value | pandas, nan, categorical-data | 1,652,197,182 |
se_72189887 | stackoverflow | DATA_SCIENCE | Comparing values in different datasets with pandas | Comparing values in different datasets with pandas
I have 4 different csv files in this format:
If there is a date in the other three files that match with a date in the first file I want to append that entire row next to the row in the first file with the matched date.
Any idea how to do it? I have tried iterating... | https://stackoverflow.com/questions/72189887/comparing-values-in-different-datasets-with-pandas | python, pandas, csv | 1,652,199,812 |
se_72189768 | stackoverflow | DATA_SCIENCE | Is it possible to manipulate negative time values in Python? | Is it possible to manipulate negative time values in Python?
Is there a way to generate negative time values in Python?
I want to generate a time range ranging from -4 minutes to a variable positive time (between 5 to 10 min), something like this:
import datetime
import pandas as pd
time_range = range(-datetime.time(m... | https://stackoverflow.com/questions/72189768/is-it-possible-to-manipulate-negative-time-values-in-python | python, pandas, datetime, python-datetime | 1,652,199,275 |
se_72191071 | stackoverflow | DATA_SCIENCE | How to create a new column with the percentage of the occurance of a particular value in another column in a DataFrame | How to create a new column with the percentage of the occurance of a particular value in another column in a DataFrame
I have a column, it has A value either 'Y' or 'N' for yes or no. i want to be able to calculate the percentage of the occurance of Yes. and then include this as the value of a new column called "Perce... | https://stackoverflow.com/questions/72191071/how-to-create-a-new-column-with-the-percentage-of-the-occurance-of-a-particular | python, pandas, dataframe | 1,652,205,705 |
se_72201363 | stackoverflow | DATA_SCIENCE | Pandas: Multiplying a value extracted from a DataFrame to column values in another DataFrame | Pandas: Multiplying a value extracted from a DataFrame to column values in another DataFrame
What I have:
I have two DataFrames. The first one df1 contains cartesian coordinates and some values related to some elements. It looks like this:
X Y Zn Pb Ag Cu Mo Cr Ni Co Ba
0 431434.79 ... | https://stackoverflow.com/questions/72201363/pandas-multiplying-a-value-extracted-from-a-dataframe-to-column-values-in-anoth | python, pandas, dataframe | 1,652,273,316 |
se_72239474 | stackoverflow | DATA_SCIENCE | Calculate value based on previous value and multiplication | Calculate value based on previous value and multiplication
I am trying to do something which is very simple in excel, but I cant seem to find the way the way to do it in python. I want to calculate the next value in a dataframe, based on the current value + percentage, similar to the excel version: | https://stackoverflow.com/questions/72239474/calculate-value-based-on-previous-value-and-multiplication | python, pandas, dataframe | 1,652,525,265 |
se_79790153 | stackoverflow | DATA_SCIENCE | How to change names of pandas MultiIndex using Styler | How to change names of pandas MultiIndex using Styler
Let's assume we have the following:
midx = pd.MultiIndex.from_product(
[[0, 1], [0, 1], [0, 1]],
names=['L1', 'L2', 'L3'])
df = pd.DataFrame({"col": list(range(8))}, index=midx)
Now, for visualization purposes, I want the names of the MultiIndex to be ['le... | https://stackoverflow.com/questions/79790153/how-to-change-names-of-pandas-multiindex-using-styler | python, pandas | 1,760,444,233 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.