0

I exported some data from Python/pandas to Excel, and it includes a column that represents the order. Example:


+----+---------+------------------+------+------+---------+
|    | Name    | Task             | Team | Date | Month   |
+----+---------+------------------+------+------+---------+
| 0  | John    | Market study     | A    | 1    | Month 1 |
+----+---------+------------------+------+------+---------+
| 1  | Michael | Customer service | B    | 1    | Month 1 |
+----+---------+------------------+------+------+---------+
| 2  | Joanna  | Accounting       | C    | 1    | Month 1 |
+----+---------+------------------+------+------+---------+
| 3  | John    | Accounting       | B    | 2    | Month 1 |
+----+---------+------------------+------+------+---------+
| 4  | Michael | Customer service | A    | 2    | Month 1 |
+----+---------+------------------+------+------+---------+
| 5  | Joanna  | Market study     | C    | 2    | Month 1 |
+----+---------+------------------+------+------+---------+
| 6  | John    | Market study     | A    | 1    | Month 3 |
+----+---------+------------------+------+------+---------+
| 7  | Michael | Customer service | B    | 1    | Month 3 |
+----+---------+------------------+------+------+---------+
| 8  | Joanna  | Accounting       | C    | 1    | Month 3 |
+----+---------+------------------+------+------+---------+
| 9  | John    | Customer service | A    | 2    | Month 3 |
+----+---------+------------------+------+------+---------+
| 10 | Michael | Accounting       | B    | 2    | Month 3 |
+----+---------+------------------+------+------+---------+

The problem is that when I import the file back into pandas, for my computer, the column on the far left that represents order is not taken into account; whereas for other people, it is. Why, and what's the solution?

smci
  • 32,567
  • 20
  • 113
  • 146
FARRAF
  • 205
  • 2
  • 8
  • Can you please clarify your statement a bit? Does your excel file have the index column (far left column) and when you import it using `pandas` it goes away? – ParalysisByAnalysis Sep 24 '19 at 22:19
  • Hi, my code does not have column of index. However when I export to excel it does. When I import that same excel file, for some people it load the index column as a column in the dataframe; however for my computer it does not. – FARRAF Sep 24 '19 at 22:21
  • When you export to excel set index=False. `df.to_excel(index=False)` – Michael Gardner Sep 24 '19 at 22:30
  • *"I exported some code to excel (format)"* Err, no. You exported some *data* to Excel. And you didn't tell us where you exported it from, I thought you mean some spreadsheet package, but you meant "exported from pandas". We can't know from where you exported it. You have to state your issue. – smci Sep 24 '19 at 22:40
  • The *"column on the far left that represents order"* is called the **index**. So your issue is either *"when I export data (from pandas) to Excel, the index is dropped"* or else *"when I read the Excel file into pandas, the index is dropped"*. – smci Sep 24 '19 at 22:42
  • yes, seems like a bad question, sorry about that – FARRAF Sep 24 '19 at 22:48
  • FARRAF, I never said it was a bad question, I get that you're new, I'm trying to welcome you to SO and help you learn the terminology to ask questions so you get good results. – smci Sep 24 '19 at 22:52

1 Answers1

0

use df.to_excel(file.xlsx, index=False) to save to file.xlsx without the index

Olivier Cruchant
  • 3,747
  • 15
  • 18