0

I have 2 dataframes with 84 rows, clearly the same lengths, but when i want to concat them to 1 df (concat by column - to have the name, Edge and Offset to the right of Latitude and Longitude), i get this error,.

what is going on?

     Latitude  Longitude
0   45.403538 -75.735729
1   45.403506 -75.735699
2   45.409095 -75.722588
3   45.409069 -75.722552
4   45.413496 -75.714184
..        ...        ...
79  45.415609 -75.644769
80  45.416073 -75.645726
81  45.416193 -75.638802
82  45.416172 -75.638223

[84 rows x 2 columns]

  name Edge  Offset
0    TUN-W    1    3000
1    TUN-E    2    3000
2    BAY-W    5  102510
3    BAY-E    6  102579
4    PIM-W    5  186035
..     ...  ...     ...
37  PTSTTW   33   52710
38  PTSTTE   34   18997
39   PAG11   40   24362
40   PAG14   50    9927
41  PHND15  177   11662

[84 rows x 3 columns]

This is my code liner

output_df = pd.concat( [output_df, input_df], axis=1)
Ethan777
  • 23
  • 7
  • 1
    Does this answer your question? [Pandas concat: ValueError: Shape of passed values is blah, indices imply blah2](https://stackoverflow.com/questions/27719407/pandas-concat-valueerror-shape-of-passed-values-is-blah-indices-imply-blah2) – Raj Srujan Jalem Jul 16 '20 at 15:10
  • Is `output_df = pd.concat( [output_df.reset_index(drop=True), input_df.reset_index(drop=True)], axis=1)` acceptable? – Balaji Ambresh Jul 16 '20 at 15:10
  • yea i alr did all my research on other stack posts but those egs r really complicated. i just needed smth simple coz i know myself that my component dfs can be printed out. so it shld not have been that complicated – Ethan777 Jul 16 '20 at 15:16

1 Answers1

1

I got it:

 name Edge  Offset
0    TUN-W    1    3000
1    TUN-E    2    3000
2    BAY-W    5  102510
3    BAY-E    6  102579
4    PIM-W    5  186035
..     ...  ...     ...
37  PTSTTW   33   52710
38  PTSTTE   34   18997
39   PAG11   40   24362
40   PAG14   50    9927
41  PHND15  177   11662

The indexing was messed up. Somewhere in the middle, the index resets to 0 instead of counting up to 84.

So i did a segments_df = segments_df_start.append(segments_df_end).reset_index() (was in earlier part of my code) to fix the indexing for that dataframe before I pass it over.

So ALWAYS remember to check your indexes and .reset_index() , when troubleshooting!!

Red
  • 26,798
  • 7
  • 36
  • 58
Ethan777
  • 23
  • 7