I am experiencing this error with the code below: I want to save the table I am scraping from wikipedia to an Excel file – but I can’t work out how to adjust the code to get the data list from the terminal to the Excel file using to_excel. I can see it works for a similar problem when a
Tag: dataframe
Filling column based on conditions
In the DataFrame below I am trying to update the Value column based on the following conditions, if Action is Sell check if the Status is not – if both the conditions are true then the first two characters of the Country needs to be updated as the Value column else if Status column is – and the Action column
Yahoo Finance API yf.Ticker(ticker).info to CSV problem
When I’m using I get a dataframe in response When I use I’m receiving a list from Yahoo finance API. How can I transform this list to a Dataframe in Pandas? So I could use How can I save yf.Ticker(ticker).info data to a csv? I don’t understand how I can change this list into something I can write to CSV
Polars equivalent of pandas expression df.groupby[‘col1′,’col2’][‘col3’].sum().unstack()
How can i create an equivalent truth table in polars? Something like the below table into a truth table The efficiency of the code is important as the dataset is too large (for using it with apriori algorithm) The unstack function in polars is different, polars alterative for pd.crosstab would also work. Answer It seems like you want tot do
How to take sample of data from very unbalanced DataFrame so as to not lose too many ‘1’?
I have a Pandas DataFrame like below with ID and Target variable (for machine learning model). My DataFrame is really large and unbalanced. I need to make sampling on my DataFrame because it is really large Balancing the DataFrame looks like this: 99.60% – 0 0.40 % – 1 ID TARGET 111 1 222 1 333 0 444 1 …
Update pandas cell in one dataframe from looked up value in second dataframe
Update pandas cell in one Dataframe from looked up value in second Dataframe I have a case where I need to update a cell in one Dataframe, ‘Stock’, which holds records of stock on-hand, looking up its value in a second Dataframe, ‘Items’, which is the table of all items. This is a simplified example of the Dataframes with relevant
Finding minimum value with groupby() by comparing two columns
I am trying to find a minimum number using groupby() by comparing two columns (Each containing a time duration) Sample data: Sample code: (It works for 1 column only) I want to group my data by groupby(‘Centroid_ID’) by comparing Regular_Ambu_TT and MSU_TT to get a minimum value. Answer Here is one approach Get the min per column Get a min
Looping dataframe to check for specific condition using if and loc
I have a data frame of temperatures with below columns, Requirement: To create new columns based on existing column values To create a list for future use using append List: Code: Works Doubt: I have to check all rows for each column 3 times using .loc and if condition. Is there a way to reduce checking 3 times, since the
How do I plot the frequency of an event overtime with pandas?I
I was trying to plot some data from a pandas dataframe. My table contains 10000ish films and for each of them two info: the year it got published, and a rating from 0 to 3. I am having a hard time trying to plot a graph with the pandas library that shows the number of films that received a particular
how can I apply label encoding by using a dataframe without using labelencoder etc. in Python?
I have two data frames: first: enter image description here second: enter image description here I need to do label encoding to the first data frame values by using the second data frame. I tried converting the second data frame to a dictionary and then replacing the first data frame values. such as; I couldn’t print the proper dictionary format.