data-manipulation

How to transform polars datetime column into a string column?

How to transform polars datetime column into a string column? Question: I’m trying to change a datetime column to a string column using polars library. I only want the dates on the new column: import polars as pl df shape: (139878, 1) ┌─────────────────────┐ │ date_time │ │ — │ │ datetime[ns] │ ╞═════════════════════╡ │ 2007-04-19 …

Total answers: 2

Replace all keys and manipulate values in a python dict and construct a new dict in a list

Replace all keys and manipulate values in a python dict and construct a new dict in a list Question: Dict to manipulate data = { "homepage.services.service_title_1": "Web Development", "homepage.services.service_title_2": "App Development" } The goal is to replace all data’s keys with "key" and add new "content" keys having the value of the previous/original dict(data dict) …

Total answers: 1

How to summarize the data to get separate column for each rank in pandas?

How to summarize the data to get separate column for each rank in pandas? Question: Table: Gate Status BUS Time Gate1 Vacant 102 10:00 Gate2 Occupied 105 10:01 Gate3 Vacant 114 10:00 Gate4 Occupied 123 9:55 Gate5 Occupied 127 10:00 Gate6 Occupied 126 10:01 Gate7 Occupied 106 10:01 Gate1 Vacant 101 10:15 Gate2 Occupied 113 …

Total answers: 1

Divide a selected item of a list by another column in a DataFrame and chose top results

Divide a selected item of a list by another column in a DataFrame and chose top results Question: I have the following test DateFrame: tag list Count icecream [[‘A’,0.9],[‘B’,0.6],[‘C’,0.5],[‘D’,0.3],[‘E’,0.1]] 5 potato [[‘U’,0.8],[‘V’,0.7],[‘W’,0.4],[‘X’,0.3],[‘Y’,0.2]] 5 Count is basically the number of lists in the DataFrame which I was able to get and add as a new column. …

Total answers: 1

Pandas – Equal occurrences of unique type for a column

Pandas – Equal occurrences of unique type for a column Question: I have a Pandas DF called “DF”. I would like to sample data from the population in such a way that, given a occurrence count, N = 100 and column = "Type", I would like to print a total of 100 rows from that …

Total answers: 1

Extract each item from a column of lists and then pick the top items

Extract each item from a column of lists and then pick the top items Question: I have the following DateFrame: | tag | list | | ——– | —————————————————-| | icecream | [[‘A’,0.9],[‘B’,0.6],[‘C’,0.5],[‘D’,0.3],[‘E’,0.1]] | | potato | [[‘U’,0.8],[‘V’,0.7],[‘W’,0.4],[‘X’,0.3],[‘Y’,0.2]] | The column list is a list of lists with each list having an item and a …

Total answers: 3

Find Specific Values in a Dataframe and Record the (Row, Column) Index Pair

Find Specific Values in a Dataframe and Record the (Row, Column) Index Pair Question: I have a Pandas data frame that looks like the following: Now, I want to go through the entire data frame and record the column and row index pairs (shown as just numbers for this example) for any value that is …

Total answers: 1

Create a pandas dataframe from a dictionary of dictionaries

Create a pandas dataframe from a dictionary of dictionaries Question: I have a dictionary of dictionaries similar to the following: data_dict = { ‘first_entry’: {‘a’: 345, ‘b’: 8484}, ‘second_entry’: {‘a’: 3423, ‘b’: 848} } I would like to create a dataframe of all these values, as follows: pd.DataFrame( [list(data_dict[key].values()) for key in data_dict.keys()], columns = …

Total answers: 2