pranaman

Untitled

Dec 10th, 2023
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. import pandas as pd
  2.  
  3. # Read data from csv file
  4. df = pd.read_csv('/Users/X/Library/Mobile Documents/com~apple~Numbers/Documents/file.csv')
  5.  
  6. # Determine the number of rows and columns in the new structure
  7. num_rows = len(df) // 6
  8. num_cols = 6
  9.  
  10. # Create a new DataFrame
  11. new_columns = pd.DataFrame(index=range(num_rows), columns=range(num_cols))
  12.  
  13. # Fill the new DataFrame
  14. for i in range(num_cols):
  15. new_columns[i] = df.iloc[i::num_cols].reset_index(drop=True)
  16.  
  17. # Rename the columns if needed
  18. new_columns.columns = ['Name', 'Person Type', 'ID', 'Business Title', 'Email', 'Location']
  19.  
  20. # Write modified data back to a csv file
  21. new_columns.to_csv('output_file.csv', index=False)
  22.  
Advertisement
Add Comment
Please, Sign In to add comment