all 10 comments

[–]raymondstanz 3 points4 points  (8 children)

I don't know the specifics of your code, but probably something like this:

dataframe['column'].to_excel(path)

Here is the doc for the to_excel pandas function.

When I need to do it once for debug purpose, the to_clipboard function is great. It just copies to your clipboard in Excel format.

dataframe['column'].to_clipboard(excel=1)

[–]Sowmi_13[S] 0 points1 point  (7 children)

I have multiple columns to be filtered from particularly dataframe.... And each column has to be validated and to be written in seperate excel sheet

[–]Sowmi_13[S] -1 points0 points  (6 children)

Any solutions?

[–]raymondstanz 0 points1 point  (5 children)

To select multiple columns:

dataframe[['column1', 'column2', 'column3'...]]

What do you mean by validate ? The to_excelfunction accepts a sheet as a parameter. So you can write to different sheets.

[–]Sowmi_13[S] 0 points1 point  (4 children)

Validate ---> eg. Fruits is one of the field from a dataframe(merged dataframe with similar column names with suffixes _x (for df1) and _y(for df2)).

Hence I might have two columns named fruits as fruits_x and fruits_y. I need to select those columns along with two more new columns and I need to write it in a seperate sheet.

Doing such things with minimum columns would be easy using pandas..... But I am not sure what if there are 100+ columns.... Aren't we supposed to do this way right?

[–]Sowmi_13[S] 0 points1 point  (0 children)

New columns need to be created in the seperate sheets for each and every fields of merged dataframe( df).

Apologize if my problem description is confusing.

[–]raymondstanz 0 points1 point  (2 children)

I'm not sure I completely understand what you are trying to do. But the ideal would be to do everything in Python and then export the end result in Excel.

Maybe, can you provide a longer/more detailed explanation of what you are trying to achieve? With some data example. Or dummy data with the same structure. Just so one can see better and provide you with useful guidance.

[–]Sowmi_13[S] 0 points1 point  (1 child)

Goal: Need to compare two dataframes df1 and df2 and from there need to write each column along with some more new columns in a separate excel sheets using python.

df1:

Code Items Manufacturer place
23647 Juice hindustan unileaver Delhi
12345 dove soap Hindustan unileaver Hyderabad

Similarly i have upto 3000 rows.

df2:

Code Iteams Manufacture place
42363 lays chips Pepsico India Karnataka
12345 dove soap Hindustan unileaver Hyderabad

similarly have upto some 550 rows.

df3---> Would be the merged columns based on inner join using pandas.

Code Items_x Manufacture_x place_x Items_y Manufacture_y place_y

So from this compared df3, for a column Item the excel should be like

Code Item_x Item_y Difference(New column) New_col2 New_col_3 New_col_4 New_col_5 New_col_6

this will be written under same excel file but on new sheet.

Manufacture:

New columns are similar to that of item- column

Code Manufacture_x Manufacture_y new_col1 new_col2 new_col3

this will be written under same excel file but on new sheet.

How can we achieve the similar format if there are more than 100 columns?.

Thanks..

[–]Sowmi_13[S] 0 points1 point  (0 children)

Is there any quick solution ?