This may be a really easy question but I am having a hard time to figure out.
I have two python data frames that I am trying to join, here is a snip of the information on each
enter image description here
enter image description here
What I am trying to accomplish is to add the name showing in the first dataframe to each row in the second, however when I try to do a pandas.merge its only doing one row
Let's suppose that df_1 is that in which you have columns named name and networkId, and df_2 is the dataframe to which you want to attach the name information via the key id.
Then,
merged = df_2.merge(df_1[["networkId","name"]], left_on="id", right_on="networkId", how="left")
print(merged.head())
If this is not in line with your example, please provide some initial data.
Related
I am making a data frame by concatenating several data frames .The code is given below.
summary_FR =pd.concat([Chip_Cur_Summary_funct_mode2,Noise_Summary_funct_mode2,VCM_Summary_funct_mode2,Sens_Summary_funct_mode2,Vbias_Summary_funct_mode2,vcm_delta_Summary_funct_mode2,THD_FUN_M2,F_LOW_FUNC_Summary_mode2,OSC_FUNC_Summary_mode2,FOSC_FUNC_Summary_mode2,VREF_CP_FUNC_Summary_mode2,Summary_PSRR_1KHz_funct_mode2,Summary_PSRR_20Hzto20KHz_funct_mode2])
The image of the table is given below. You can see that the 1st column don't have any name.I need to set it name as Parameter and make it as unique index column.
I tried the below code to set the name as 'Parameter' and I failed.
summary_FR.columns = ["Parameters", "SPEC_MIN", "SPEC_TYP", "SPEC_MAX","min","mean","max","std","Units","Remarks"]
# summary_FR.set_index()
May I know where I went wrong.Can someone please help me.
It helps to share the error message but that is probably an index column. You need to call reset_index on the concatenated dataframe like
summary_FR =pd.concat([Chip_Cur_,...,Summar]).reset_index()
then you can change the colun names.
You can give a name for the index in the following way:
your_dataframe.index.name = 'Parameter'
so lets say i have a pandas dataframe which has three columns, Account Number, Date, and Volume.
i want to be able to create a new dataframe with the same columns but filtered by a prompt i chose (in this case 2022-08-17) and all accounts.
in reality the sheet is much larger and has alot of accounts.
see example below:
thank you
IIUC, you need:
(df[df['Prompt'].eq('2022-08-17')]
.groupby(['Account', 'Prompt'], as_index=False)
.sum()
)
Output:
No output provided as the input format was an image
I have a excel in below format
Note:- Values in Column Name will be dynamic. In current example 10 records are shown. In another set of data it can be different number of column name.
I want to convert the rows into columns as below
Is there any easy option in python pandas to handle this scenario?
Thanks #juhat for the suggestion on pivot table. I was able to achieve the intended result with this code:
fsdData = pd.read_csv("py_fsd.csv")
fsdData.pivot(index="msg Srl", columns="Column Name", values="Value")
Trying to merge two dataframes of hockey data, both have player names (what I am trying to merge on) mind you the one with salary data only has 500 rows or so and the primary dataframe has 2000+ (if that makes a difference. Trying to merge them on name when applicable and the new df created has no rows of data in it.
Wanted to merge wherever it made sense to (ie. where both had salary data for a given player)
Let me know if something is not clear or how to upload more info as needed as I'm not seeing an option to make uploading the tables possible or if I can otherwise include more insight/info that may make my situation clearer to you when trying to help.
Thanks for what input you can kindly provide, enjoy your weekend.
Dataframes I am looking to merge on player names
When trying to merge the dataframes, I am simply trying to do so as follows
df = pd.merge(hdf, sdf, on='Player')
First reset sdf index cause now player name is index not a column:
df = pd.merge(hdf, sdf.reset_indx(), on='Player')
This is what I am trying to accomplish
1. There is a master table. So i extracted column 1,2,3 and columns 4,5,6. I need to stack them on top of one another (not side by side).
2. For this, I extracted them into two data frames and tried to append but it does not seem to work. Here is my code.
import pandas as pd
import html5lib
link = "https://en.wikipedia.org/wiki/Mobile_telephone_numbering_in_India"
tables = pd.read_html(link)[3]#select the 3rd section which is our table
base=tables.iloc[:, 0:3]
top=tables.iloc[:,3:6]
print(base)
base=base.append(top)
print(base)
Here is my output:
enter image description here
I need the rows to be added to one another. How can I do it?
think you need to use concat instead of append;
https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.concat.html
When you want to append a 2nd dataframe, you need to reassign it as follows:
base = base.append(top)