I’d like to update values in a column [‘D’] of my data frame based on the substrings contained in column [‘A’] I have dataframe df, where column D is an exact copy of column A. Column A has list of different cereal names. But I want to check if A contains a certain word and if so…
Tag: pandas
Get information from plt.hexbin
I have been using hexbing to try to improve the SPCF method, so for that I would need to get information from the plot to modify the data and then replot it with the new values. The most important data I need to modify to replot is the number of points per cell and the C value of that grid
creating pandas function equivalent for EXCEL OFFSET function
Let’s say input was I want to create an additional column that looks like this: Basically each number in offset is telling you the number of columns to sum over (from col1 as ref point). Is there a vectorized way to do this without iterating through each value in offset? Answer You use np.select. To use…
Join two dataframes by range and values
I have two dataframes like this: df1: Value Responsible 11000 Jack 21040 Dylan 12050 Jack df2: Start End 10001 20000 20001 30000 Desired output: Start End Responsible 10001 20000 Jack 20001 30000 Dylan I need to join the ‘Responsible’ column in df2, using ‘Value’ as key that is in the …
pandas groupby ignoring column
Below is my groupby function and dataset before the operation. However, the statement as written produces no change. I want this to be a single row containing sums for each category. Answer You need to enclose your list by []:
wont create a csv file [closed]
Closed. This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 12 months ago. Improve this question It still won’t create a all_data.csv file. Answer https://pandas.pydata.org/docs/ref…
pandas groupby create new columns based on col1 containing value of col2
I have a pandas dataframe that I want to group by and create columns for each value of col1 and they should contain the value of col2. And example dataframe: I want to groupby item_id, create as many columns as feature_category_id and fill them with the feature_value_id. The resultant df for the example would…
Pandas Dataframe into nested Dictionaries conversion in Python
I need a little help. I want to convert from dataframe into nested dictionaries. and i want to convert in this format: Answer We can do groupby with agg dict items
How to get strftime to output yearly quarters?
I am trying to create a list of year-quarters in python; per the documentation (https://pandas.pydata.org/docs/reference/api/pandas.Period.strftime.html), %q (I believe) should output an integer representation of calendar quarter, but instead the output I get is just %q literally. Input: Expected Output: Actu…
export a comma-separated string as a text file without auto-formatting it as a CSV
Im developing an API which should, ideally, export a conmma-separated list as a .txt file which should look like alphanumeric1, alphanumeric2, alphanumeric3 the data to be exported is coming from a column of a pandas dataframe, so I guess I get it, but all my attempts to get it as a single-line string literal…