Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pandas as pd
- # Read data from csv file
- df = pd.read_csv('/Users/X/Library/Mobile Documents/com~apple~Numbers/Documents/file.csv')
- # Determine the number of rows and columns in the new structure
- num_rows = len(df) // 6
- num_cols = 6
- # Create a new DataFrame
- new_columns = pd.DataFrame(index=range(num_rows), columns=range(num_cols))
- # Fill the new DataFrame
- for i in range(num_cols):
- new_columns[i] = df.iloc[i::num_cols].reset_index(drop=True)
- # Rename the columns if needed
- new_columns.columns = ['Name', 'Person Type', 'ID', 'Business Title', 'Email', 'Location']
- # Write modified data back to a csv file
- new_columns.to_csv('output_file.csv', index=False)
Advertisement
Add Comment
Please, Sign In to add comment