Fix Python – cartesian product in pandas

I have two pandas dataframes:
from pandas import DataFrame
df1 = DataFrame({‘col1′:[1,2],’col2’:[3,4]})
df2 = DataFrame({‘col3’:[5,6]})

What is the best practice to get their cartesian product (of course without writing it explicitly like me)?
#df1, df2 cartesian product
df_cartesian = DataFrame({‘col1′:[1,2,1,2],’col2′:[3,4,3,4],’col3’:[5,5….

Fix Python – How to merge multiple dataframes

I have different dataframes and need to merge them together based on the date column. If I only had two dataframes, I could use df1.merge(df2, on=’date’), to do it with three dataframes, I use df1.merge(df2.merge(df3, on=’date’), on=’date’), however it becomes really complex and unreadable to do it with multiple dataframes.
All dataframes have one….

Fix Python – Python Pandas merge only certain columns

Is it possible to only merge some columns? I have a DataFrame df1 with columns x, y, z, and df2 with columns x, a ,b, c, d, e, f, etc.
I want to merge the two DataFrames on x, but I only want to merge columns df2.a, df2.b – not the entire DataFrame.
The result would be a DataFrame with x, y, z, a, b.
I could merge then delete the unwanted columns….

Fix Python – How to merge dictionaries of dictionaries?

I need to merge multiple dictionaries, here’s what I have for instance:
dict1 = {1:{“a”:{A}}, 2:{“b”:{B}}}

dict2 = {2:{“c”:{C}}, 3:{“d”:{D}}

With A B C and D being leaves of the tree, like {“info1″:”value”, “info2″:”value2”}
There is an unknown level(depth) of dictionaries, it could be {2:{“c”:{“z”:{“y”:{C}}}}}
In my case it represents a directo….

Fix Python – pandas three-way joining multiple dataframes on columns

I have 3 CSV files. Each has the first column as the (string) names of people, while all the other columns in each dataframe are attributes of that person.
How can I “join” together all three CSV documents to create a single CSV with each row having all the attributes for each unique value of the person’s string name?
The join() function in panda….

Fix Python – Apply pandas function to column to create multiple new columns?

How to do this in pandas:
I have a function extract_text_features on a single text column, returning multiple output columns. Specifically, the function returns 6 values.
The function works, however there doesn’t seem to be any proper return type (pandas DataFrame/ numpy array/ Python list) such that the output can get correctly assigned df.ix[: ,….

Fix Python – Pandas Merging 101

How can I perform a (INNER| (LEFT|RIGHT|FULL) OUTER) JOIN with pandas?
How do I add NaNs for missing rows after a merge?
How do I get rid of NaNs after merging?
Can I merge on the index?
How do I merge multiple DataFrames?
Cross join with pandas
merge? join? concat? update? Who? What? Why?!

… and more. I’ve seen these recurring questions askin….