I am trying to append a column to my DataFrame that is based on the values that are referenced by indicated column names. I have the following DataFrame: The values under “Select” are referencing the values that are under the column number that “Select” shows. For example, for row 0, &…
Tag: pandas
How can we create separate excel sheets using python pandas?
For ex: I have one excel file as my input, consisting of 50K records of employees. Employees are working in different companies A,B, and C. How can we filter this input excel file on the basis of companies and create new output Excel file. Which consist of separate sheets For Companies A,B, and C. In output e…
How do I extract the last trading day from a csv file?
I have a csv file which contains 30 years of stocks data. A portion of it looks like this: How can I extract the last trading date of a specific month of a specific stock, say the last trading month of June 2018 of stock s_0003? This is my code, but it doesn’t seem to be working for me because
Filter and calculate % of a dataframe column
I am trying to calculate the % of men and women in a dataframe column named “gender”. “gender” is defined as an object taking 3 values : “Man” “Woman” “nan” (NA). I did this : But it returns 0.0% for both. When i check ‘total’ value it re…
How do I melt a pandas dataframe?
On the pandas tag, I often see users asking questions about melting dataframes in pandas. I am gonna attempt a cannonical Q&A (self-answer) with this topic. I am gonna clarify: What is melt? How do I use melt? When do I use melt? I see some hotter questions about melt, like: Convert columns into rows with…
escaping square brackets from string in dataframe
I have a dataframe where i am try to clean the data from all cols. There are some annomalies in teh data like this: “[n], [ta], [cb]” basically anything in square brackets i want to ignore and replace with a space. I have this: this works except I still get the square brackets in the data but they…
Remove series of characters in pandas
Somewhat of a beginner in pandas. I am trying to clean data in a specific column by removing a series of characters. Currently the data looks like this: I need to remove the (F) I used … df[‘Column A’]=df[‘Column A’].str.replace(‘[(F)]’,’ ‘) This successfully removed the (F) but it also removed the other F le…
inserting missing categories and dates in pandas dataframe
I have the following data frame. I want to add in all score levels (high, mid, low), for each group (a, b, c, d), for all dates (there are two dates – 2020-06-01 and 2020-06-02) I can add in the score categories for all subjects with the following, but i am having trouble adding date in as well the expe…
how to apply Pandas.set_option (Python) to pandas.style objects
I have noticed that when we set some options for pandas DataFrames such as pandas.DataFrame(‘max_rows’,10) it works perfectly for DataFrame objects. However, it has no effect on Style objects. Check the following code : Which will result in : I do not know how to set the properties for Style objec…
Is there anyway to convert specific text data to csv format and give Header names in python?
I have this format of the dataset in a text file. Here the dataset link is https://drive.google.com/file/d/1RqU2s0dqjd60dcYlxEJ8vnw9_z2fWixd/view?usp=sharing I want to give the left side value as column name and right side values will be a row format. Output should be I have tried with text to CSV but not wor…