I want to use Python to create an Excel pivot table. Can't find any working code to accomplish this, anyone know a library I could use?

like
Posting as :
works at
You are currently posting as works at

import pandas as pd

# Sample data
data = {
'Date': ['2023-01-01', '2023-01-02', '2023-01-03', '2023-01-01', '2023-01-02'],
'Region': ['East', 'West', 'East', 'North', 'South'],
'Sales': [100, 150, 200, 130, 170]
}

df = pd.DataFrame(data)

# Create a pivot table
pivot_table = df.pivot_table(index='Date', columns='Region', values='Sales', aggfunc='sum')

# Write to an Excel file
excel_file = 'pivot_table.xlsx'
with pd.ExcelWriter(excel_file, engine='xlsxwriter') as writer:
pivot_table.to_excel(writer, sheet_name='PivotTable')

# Get the xlsxwriter workbook and worksheet objects.
workbook = writer.book
worksheet = writer.sheets['PivotTable']

# Add some formatting
format1 = workbook.add_format({'num_format': '#,##0.00'})

# Set the column width and format
worksheet.set_column('A:A', 15, format1)
worksheet.set_column('B:D', 10, format1)

like

Give chatgpt a try for things like that! Had a lot of success there with excel help. Even just asking basic things, what is the best way to do [insert thing]. Whether or not it is the best way, not always sure, but it is always a way to do it! Definitely give it a try next time you are stuck on something.

I second the chat gpt recommendation. I will sometimes describe my df and what I want to accomplish and then work back and forth with it until I have what I want. Works surprisingly well tbh

f

Literally use .pivot_table() in pandas, lol I’m sure you can find some examples if you google it

I think ChatGPT can help you

Related Posts

Which do you prefer?

“Give me a deadline and I’ll get the work done”
or

“when I get this done I’ll let you know and we can figure out when the client will see it.”

like

Looking for experienced auditors in the Tampa area. Private companies, manufacturing, construction, professional services, healthcare, nonprofit, government, benefit plans, all industries!

like
like

Any one here who is serving notice period in EY and got hike letter

What’s MBA sponsorship policy like at T2 firms (EY-P, S&, OW, etc)? is competition tough? For EYP and S&, is the policy the same as EY and PWC or is there a separate policy?

like

Are the google salaries listed on levels.fyi show yearly stock of is the stock part split across multiple years?

like

Hi sharks,
How is the career growth for a Salesforce developer in the market in near future.

like

What roles would I need to look into to pivot to become an SE? Any references on companies to look at Healthcare Sales & business development background 5 YOE?

Year 1: Should I be applying for analyst roles and studying for CFA if I know I don't want to stay in audit or work on getting my CPA and wait another busy season before I apply/request for transfer?

like

What are reasonable exit opportunities from transaction advisory/fdd? I am considering a position in this but am concerned with getting stuck too far down the road.

like

Anyone stop logging all their hours?
I did and it's killing me because now I'm working till 2 am, but its not showing on paper. I o ly show 8 or 9 hours. But, I would rather not get yelled at from the client or director for going over budget. The budget is super tight, like 1.5 hours per workpaper and my associate already uses all of it. So nothing is left for review. Why do partners do this to us?

like

How do I show my supervisors I am ready for a promotion to manager?

like

Hi everyone, I have created this bowl to answer questions that professionals might have about immigrating to Canada. I am a Regulated Canadian Immigration Consultant in Vancouver,BC. Ask away!

like

What are the list of criteria to be promoted to AD?

like

What is the appraisal percentage in Citiustech Healthcare?

How to refer someone for a role at JPMC?
Not general refferal, but for a specific role?

like

Should I leave Deloitte for a move to a new city + a mid size firm job in a litigation practice area I’m not interested in, just for the sake of gaining law firm experience? (Been at big 4 one year graduated law school in 2021) or stay at Deloitte a little longer until I find a job in an area I actually want to learn about

Currently I pay $1900 for a brand new & modern 1BHK in the Greater NYC area. Moving to SF later this year. Any recommendations on how much to budget for SF? Will be working in Downtown area & currently got a car. I am little bit divided on whether to sell the car or move it to SF.

Looking for a good neighbourhood and ok with 30 minute commute to work.

like

Glad to be hear folks. I am sure I am not alone but I have experienced many attacks from my administration for simply answering questions about my faith in class or telling students I do not believe in abortion. Hoping to find some insights from others here in regards to still being a Christian example in public education without losing my job.

likehelpful

Additional Posts in Data Analytics & Data Science

I’ve got about 20 years cross channel experience in marketing, split between big brands and startups, and I’m considering pivoting into a data science/data analyst role. I know it will initially be a step back in comp but is it at all realistic for a person with certificate level experience in data analysis but a decent marketing management background to expect $150-200k comp or is that mostly for degreed candidates (or not realistic at all)? Any guidance here is greatly appreciated.

like

This bowl is crickets and I think we should make it much bigger. Anybody have any ideas how to get more people in his bowl?

like

Does anyone here have experience building product analytics? I am the first product analyst in my team and I work with approximately 6 PMs. Any help is appreciated

like

Could someone help me break down the differences between a Data Analyst vs Data Scientist vs Product Manager? And add any pros/cons from personal experience? In my mind they’re all related, but I don’t have experience working with any of these roles.

Here is my go-to interview question, "What is the difference between data science and data analytics?"

What questions does everyone else include when interviewing or is the best question you've been asked in an interview?

like

How many folks here have gone from data science into ML? And how many folks here have gone from data science into product management, or want to? Would love to hear some views here about career paths for data science people.

like

Hi all,
I graduated during Covid with a double major in business administration and business management with a minor in marketing and magically ended up in sales because I needed a job. I’m about to take a data analytics course to make an attempt to break into that field. I’m currently looking for a mentor to help guide me during this time. Also, if anyone is willing to look over my resume and give me tips on how to make it more presentable for recruiters in DA that would be very helpful. Thanks

like

Hi All, I am currently a Data Analyst with 1 year of experience and pursuing a masters in Computer Science (expected to graduate 5/2023). I am looking to transition into an entry Data Scientist role (preferably remote or Philadelphia, PA). Can someone refer me or let me know who is hiring?

I can provide my resume if needed.

Can anyone please share what salaries for Data Analysts are like in Bangalore, India for someone with about 2-4 years experience? Roughly how much per year can Data Analysts for large organizations expect to make?

like

Does anybody here do any side work for extra income using their data expertise? I would love ideas that I could do from ~5-15 hours a week. Tutoring is the only thing that comes to mind immediately. Thanks in advance!

helpful

I have a JP Morgan code interview happening soon for a data science position. Anything I should know before I get started?

like

What is the market like for entry level data scientists/ data analyst. I have a graduate certificate in data science and have spent the last 27 years as a mainframe dev so I have great SQL skills.

like

Would like some opinions about how likely it is to make product analytics self serve by PMs? Anybody have success here? Or is it hopeless to think that product managers can pull their own data, look at their own dashboards, and do basic data tasks themselves?

like

I like to pursue in the data science field. I have business Analyst experience but to switch to data science field could you guide me on what should I learn? Where should I start?

like

I have 5 YOE in Analytics... always thought I wanted to be a DS, but every job (even the junior ones) required experience in ML development. Though I am part of the ML project, I'm not the person develop the model. And I have a hard time when the interviewer ask about how I develop the model and what hyperparameters I tuned. I know the thought process and stuff but 'I' wasn't the one who did that part in the project. How to convince them that I could do the job without taking credit of others.

like

How is it to work as a Data Scientist at Morgan Stanley ? How os the data culture ?

like

Good morning, hope everyone is having a great week! Does anyone have any advice on breaking into an analyst role? I am currently a Senior Customer Success Manager, with a background in Operations/Process and Project Management as well. I have always enjoyed the analysis pieces of my roles and would love to expand my skills to show how qualified for a position in data analytics. Thank you in advance for the help!

like

New to Fishbowl?

Download the Fishbowl app to
unlock all discussions on Fishbowl.
That was just a preview…
Sign Up to see all discussions
  • Discover what it’s like to work at companies from real professionals
  • Get candid advice from people in your field in a safe space
  • Chat and network with other professionals in your field
Sign up in seconds to unlock all discussions on Fishbowl.

Already a user?
Login here

Share

Embed this post

Copy and paste embed code on your site

Preview

Download the
Fishbowl app

See what’s happening in your industry
from the palm of your hand.

A phone with Fishbowl app

Scan your QR code to download
Fishbowl app on your mobile

Download app

Sign up for free to view this conversation on Fishbowl

By continuing you agree to Terms of Use and Privacy Policy

Already have an account? Log in

Sign up for free to continue using Fishbowl

By continuing you agree to Terms of Use(New) and Privacy Policy(New)
Messaging rates may apply

Already have an account? Log in

For account settings, visit Fishbowl on Desktop Browser or

General

Legal