I have response from API call as shown below How can I convert this into proper dataframe. I tried below code its creating the columns are properly. I want each element of the API response as seperate column. For eg. ‘position’: {‘lat’: 47.464699, ‘lon’: 8.54917} should be …
Tag: pandas
Complex nested dict to pandas with multilevel index
I have a complex nested dictionary with multiple levels. I wish to create a multilevel index pandas dataframe from the dict. The dict takes the format: Basically, there are 3 arrays, each containing dicts. In the outer most level, bucket_0, we have X number of foo dicts. In the next level, bucket_1, we have Y…
Two parameter non-linear function for modeling a 3-D surface
I’m interested in modeling this surface with a simple equation that takes in two parameters (x,y) values and produces a z value. Ideally an equation that has a simple form. I have tried Monkey Saddle, polynomial regression (3rd and 4th order) and also multi-linear and log-linear OLS with some success (R…
Multiple Seaborn Heatmaps from Pandas Dataframe
I have a Pandas dataframe that looks like this: Where there are ~60 stores and the ratings range from 0 – 2. I would like to create a 6×5 grid Seaborn of heatmaps, with one heatmap per store. I would like for the x-axis to be the days and for the y-axis to be the times. I tried this: This
In Pandas dataframe, how to append a new column of True / False based on each row’s value?
I’m trying to create a dataframe of stock prices, and append a True/False column for each row based on certain conditions. The original 9 rows by 4 columns dataframe contains only the close / open / upper / mid columns. that check_conds functions returns the df nicely with the new cond1-5 columns return…
Row-level cumulative sum with condition
I have a table that looks like this. m1 m2 m3 m4 m5 m6 m7 m8 s 0 1 0 0 5 0 4 10 4 4 1 8 0 15 0 4 10 10 I need to know at which position or column the row-level cumulative sum for the first six columns (m1 to m6) either equals or exceeds
KeyError when using loc from pandas
I have a simple CSV-file which I import as a dataframe. Using df.columns I get the following: Index([‘Unnamed: 0’, ‘age’, ‘sex’, ‘bmi’, ‘bp’, ‘s1’, ‘s2’, ‘s3’, ‘s4’, ‘s5’, ‘s6’, …
Column merge and shift elements in a Dataframe row
I have a dataframe as follows: In the last row (and several others in the full dataframe) the negative signs are misplaced. My question is if a negative sign is there at i-th position then it should merge i+1 th element and shift all other row elements to the left such that it the final output should be Answe…
Filling missing data using a custom condition in a Pandas time series dataframe
Below is a portion of mydataframe which has many missing values. I would like to replace the NANs in each column using a specific backward fill condition . For example, in column (A,a) missing values appear for dates 16th, 17th, 18th and 19th. The next value is ‘4’ against 20th. I want this value …
Python – Parse text file with no delimiter and dynamic width values
My goal is to parse a text file in Python that has no headers therefore no columns names and no delimiters. A sample of the original file looks as follows: I tried to import the file into an Excel file but since it has no delimiter nor fixed-width, each value of the row is wrapped within one cell (cell A).