Please, I have a dataframe that is listed in ascending order. My goal is to average similar numbers (numbers that are within 10% of each other in ‘both directions’) and concate their ‘Bell’ name together. For example, the image shows the input and output dataframe. I tried coding it but I stuck on how to prog…
Tag: pandas
How to save pandas textmanipulation as csv in the correct form
I have a *.txt file with numbers. I want to eliminate the spaces. The raw data looks like this If I use the following I get which I want. But if I save it to csv with I get as file values: If I use the quoating = csv.None or 3 (same) The file looks like: Just using space or
How do I append a repeating list to a dataframe?
I have a list sub = [“A”,”B”,”C”,”D”,”E”,”F”] and a dataframe of the following format: I need to write a code for my dataframe to finally look like the following format: Answer You can create a cycle using itertools.cycle, and cut it to t…
Python: Rows to Column in Pandas Dataframe
I have following dataframe: Out: There are different metrics at column “metric_name” with its own value. To have a better dataset for time series forecasting I want to convert my Dataframe. I want every single metric in “metric_name” as new column in the dataset. See here all different…
Fill a dataframe with the output of a loop
I’m trying to concatenate the output of a loop into dataframe. This example is totally unrealistic, but just to try to demonstrate my problem, my error and the result I need. My output: Good output Answer You can do
compare 2 string columns in data frame and add 1 to key if different
I’m having a hard time trying to figure this out, I have a data frame with multiple columns after merging 2. I have 2 list: I need to compare each group of variables and if they are different add 1 to the key column I was trying to use something like this: Answer I would avoid loops. Is there any
adding consequently items of a list to a dataframe
As a practice, I have created the following dataset of reading books: Then I added a fourth column as follows And now I would like to add as follows (I mean as rows 5 and 6) the following item, always by using the list I have tried adding other titles the following code which does not work: Since I am
Pandas TypeError: unhashable type: ‘list’ when importing from csv
I’m trying to clean some data from a csv file. Here’s an example of the data I’m importing. What I’m trying to do is split the cell by the first comma. The data before the comma goes to one column, the data after goes to another. I’ve set up a function to handle the data: The csv…
Python: How to filter a Pandas DataFrame using Values from a Series?
Context I am currently processing some data and encountered a problem. I would like to filter a Pandas DataFrame using Values from a Series. However, this always throws the following Error: ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all(). Code Question…
How to skip some x-values in matplotlib plots to reduce the density?
I’m trying to plot minimum and maximum daily temperature values for last 20 years. Since there are too many days in between, my plot graph looks too complicated. How can I make change the frequency of days to reduce the density of my graph? In other words, I want to set that it gets the weather of one d…