How to merge 2 CSV files together by multiple columns in Python
I believe you need to use ['Date', 'Ticker']
instead of just 'Date'
. Also you might need to specify the how
argument depending on what you want.
Use pandas to combine 2 CSV files
IIUC you want to be able to tell you function which column is to be handled as Z
in df2
and then concat both lists:
def concat_df_on_z(df1, df2, z_col):
df2 = df2[['X', 'Y', z_col]].rename(columns={z_col: 'Z'})
return pd.concat([df1, df2])
df3 = concat_df_on_z(df1, df2, 'B')
print(df3)
Output:
X Y Z
0 626066.4 234058.2 6.69
1 626066.4 234059.2 6.89
2 626066.4 234060.2 7.06
0 627839.0 232463.4 14.46
1 627839.0 232463.1 14.46
Related Topics
Python Pandas .Isnull() Does Not Work on Nat in Object Dtype
Return Value from Python-Shell as Response
How to Run Linux Terminal Command in Python in New Terminal
How to Remove Hashtag, @User, Link of a Tweet Using Regular Expression
Json Dump in Python Writing Newline Character and Carriage Returns in File.
Finding the Most Frequent Character in a String
Regex to Remove Commas Before a Number in Python
Adding Different Sized/Shaped Displaced Numpy Matrices
Rotate Tick Labels for Seaborn Barplot
Loading and Parsing a Json File With Multiple Json Objects
Python: Plotting Percentage in Seaborn Bar Plot
Printing Lists in Python Without Spaces
Keras Valueerror: Input 0 Is Incompatible With Layer Conv2D_1: Expected Ndim=4, Found Ndim=5
A Way to Quick Preview .Ipynb Files
How to Create Different Variable Names While in a Loop
How to Determine Whether a Pandas Column Contains a Particular Value
How to Remove Strings Present in a List from a Column in Pandas