I would like to achieve what it’s described here: stackoverflow question, but only using standard pandas. I have two dataframes: Fist Second: I want to join the two dataframes such that my final dataframe is identical to the first one, but it has also the book_count column with the corresponding values …
Tag: dataframe
Splitting object data into new columns in dataframe
i have a dataframe with column business_id and attributes with thousands of rows like this: how do create new column for each attribute with the value to the business id ? and if it’s not applicable to that business id, it will specify false. example: while also noting that there are some attributes wit…
Converting dict to DataFrame gives too many rows
I am trying to convert a dict to Pandas DataFrame as the following: And when I print out the DataFrame, I see the following output: I expect to see 1 row only in the DataFrame but it gives 5. And I cannot understand why. What am I doing wrong here? Answer You’re not doing anything wrong. Since tags is a
Python Pandas: Append column value, based on another same column value
I have a pandas dataframe like this. I want to append Town value, which is based on row have the same Source, Level and County value. I have tried isin, groupby, diff(but my value is str), but still not figure out. Image below is what I want to get. Really appreciate your help! Answer The way we can make this
Newbie – customer profiling in Python (pandas) using loc()
I’m a newbie, so please excuse me if I use incorrect terms. I have a df with customer purchasing info and customers are identified by a unique user_id. Each item a user_id buys in each transaction creates a new row (if a customer buys 5 products in 1 transaction, 5 different rows are created with that p…
Getting data with diferent currencies from Bloomberg API,using python?
I am trying to extract data from Bloomberg. I need data for multiple fields with diferent currencies. I can’t get what I need from this answer https://github.com/alpha-xone/xbbg Can anyone help, please?. for a “specifc time” and on a “period of time”? I tried the following code b…
Python pandas extract data from nested list
For a personal project, I’m calling data from the Google Books API and uploading the fields I want to mySQL. I’ve successfully made the API request and received data. The data received is nested and i want to place this in a dataframe. Now my code works with the “first” column (no inde…
Find max by year and return date on which max occurred in Pandas with dates as index
I have this dataframe I would like to compute the max for each year and the date where it happens. I am struggling because I would like to keep indeed the date as index. Indeed I read it as: I know that I could resample as but in this case I would lose the information about the location of the
Using Python maintain clean a text file on a specific format consistent across each line
I have got a unique use case. I have got a txt file in the following format where every line starts with “APA” and ends with “||” (varies in length and content, does not matter) In some lines however, due to unknown reasons, some of these lines are split like so: Technically this line …
Python pandas conditional ffill. Fill the month beginning value till that month’s end
The code below produces sample dataframe The value on 1st of December is as follows Which outputs 9 My question is how to use “ffill” method to have this value 9 for all days of December? I want the month beginning value to be filled till end of that month Answer Replace values for all days except…