data-analysis

Pandas Drop rows if String has numeric (floats of 4 decimals/5 numbers)

Pandas Drop rows if String has numeric (floats of 4 decimals/5 numbers) Question: I have a long list dataframe that has texts similar to the example provided in the image. dataframe is called gbs2. I want to gbs2.drop rows with numerical values that has 4 decimal places or 5 numbers ("1.2345" or "12345") Code used: …

Total answers: 1

How to remove all rows of a datframe column that contain a question mark instead of occupation

How to remove all rows of a datframe column that contain a question mark instead of occupation Question: This is my attempt: df[‘occupation’]= df[‘occupation’].str.replace(‘?’, ”) df.dropna(subset=[‘occupation’], inplace=True) but it is not working, How do i remove all of the rows of the occupation column that i read from a csv file that contain a ? …

Total answers: 3

How to add rows to a dataframe when values are recursively dependent?

How to add rows to a dataframe when values are recursively dependent? Question: I have a data frame with columns a and b df = pd.DataFrame(data = [[3, 6], [5, 10], [9, 18], [17, 34]], columns = ["a", "b"]) The structure of this data is as follows, if at denotes the value of column a …

Total answers: 1

How does the below code produce more than 10 outputs as the slice operation must be restricting it to 10 values?

How does the below code produce more than 10 outputs as the slice operation must be restricting it to 10 values? Question: (autos["date_crawled"] .str[:10] .value_counts(normalize=True, dropna=False) .sort_index() ) here we are working with Ebay sales data(https://www.kaggle.com/datasets/viveksinghgulia/autoscsv) Running the above code gives the followiing output 2016-03-05 0.025327 2016-03-06 0.014043 2016-03-07 0.036014 2016-03-08 0.033296 2016-03-09 0.033090 2016-03-10 …

Total answers: 1

extracting a string from between to strings in dataframe

extracting a string from between to strings in dataframe Question: im trying to extract a value from my data frame i have a column [‘Desc’] it contains sentences in the folowing format _000it_ZZZ$$$- _0780it_ZBZT$$$- _011it_BB$$$- _000it_CCCC$$$- I want to extract the string between ‘it_’ and ‘$$$’ I have tried this code but does not seem …

Total answers: 2

Parse word doc using python to find all words with _

Parse word doc using python to find all words with _ Question: I am looking to parse a word document in python and I want to load that in a DataFrame (DF) to print all the words in that DF that contains a _(underscore). Any sample code on this would be great? I have tried …

Total answers: 1

Polars equivalent of pandas expression df.groupby['col1','col2']['col3'].sum().unstack()

Polars equivalent of pandas expression df.groupby['col1','col2']['col3'].sum().unstack() Question: pandasdf=pd.DataFrame( { "A": [1, 2, 3, 4, 5], "fruits": ["banana", "banana", "apple", "apple", "banana"], "B": [5, 4, 3, 2, 1], "cars": ["beetle", "audi", "beetle", "beetle", "beetle"], "optional": [28, 300, None, 2, -30], } ) pandasdf.groupby(["fruits","cars"])[‘B’].sum().unstack() How can i create an equivalent truth table in polars? Something like the …

Total answers: 1

Combining 4 sets of data in python

Combining 4 sets of data in python Question: I have four separate sets of data for each of the 4 quarters in the year, the columns are identical within all. What is a python function I can use to combine them into one master data set? Thank you! Asked By: Niamh || Source Answers: You …

Total answers: 2

Formating a new table using python. Punch in and Punch out employee data

Formating a new table using python. Punch in and Punch out employee data Question: I have a list of employee punch date: that needs to be formatted into a different table LIKE: each new row has to be a new date. I have gotten started with variables, however I am failing at iterating through the …

Total answers: 1