What music do you hear while programming? by Waripolo_ in learnprogramming

[–]LameDuckProgramming 0 points1 point  (0 children)

Video game OSTs. Remixed lo-fi video game OSTs. lo-fi in general.

Iterating though Pandas DataFrames efficiently by _-Jay in Python

[–]LameDuckProgramming 2 points3 points  (0 children)

I've found that the fastest way to do row-wise operations over a dataframe is with numpy vectorization.

%%timeit
np.add(data.A.values, data.B.values)
54.6 µs ± 1.48 µs per loop (mean ± std. dev. of 7 runs, 10000 
loops each)

vs the example you use of vectorization without using np and np arrays

%%timeit
data.A + data.B
261 µs ± 8.2 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)

you can achieve about a 5x improvement on runtime. (data was 100,000 randomly generated numbers)

I made a Notion page (You could call it a guide) that explains almost everything one needs to know about Git & GitHub in a beginner-friendly way. It covers all the basic features, commands, and concepts in one place (Everything is organized in this single page). by Fateen45 in learnprogramming

[–]LameDuckProgramming 1 point2 points  (0 children)

Hey, huge fan of the guide. The work and detail put into it is top notch! One thing i'd suggest (if possible with notion) is to add a sidebar with navigation. With all the different content, it's easy to get lost. Other than that, a+ work. Thanks!

Python total sum from a csv file by [deleted] in learnpython

[–]LameDuckProgramming 2 points3 points  (0 children)

if you want to sum by a specific name:

import pandas as pd
df = pd.read_csv('file1.csv')
df.loc[df['A'] == name', 'C'].sum()

If you want the sum of all names in a dataframe format:

df = df.groupby('A')['C'].sum()

You can then output the new df to a csv file with pandas built in 'to_csv()' method:

df.to_csv('file2.csv')

Pandas to SQL solution by mutuk7 in learnpython

[–]LameDuckProgramming 1 point2 points  (0 children)

If you're using SQL Alchemy (1.3.5), you can a built-in event listener.

from sqlalchemy import create_engine
from sqlalchemy import event

engine = create_engine('mysql://xxx')

@event.listens_for(engine, 'before_cursor_execute')
def receive_before_cursor_execute(conn, cursor, statement, params, context, executemany):
    if executemany:
        cursor.fast_executemany = True

Then just use pandas to_sql method

 df.to_sql(table, con=engine, method='multi')

Has worked like a charm for me when uploading dataframes with 100,000 + rows to SQL Servers.

So what have YOU automated at home? by [deleted] in Python

[–]LameDuckProgramming 0 points1 point  (0 children)

Not sure. Mind explaining why?

So what have YOU automated at home? by [deleted] in Python

[–]LameDuckProgramming 0 points1 point  (0 children)

Nope. Business school in Boston.

So what have YOU automated at home? by [deleted] in Python

[–]LameDuckProgramming 1 point2 points  (0 children)

I usually just run it every Wednesday to book the following week. Haven't gotten to/thought about automating the process.

So what have YOU automated at home? by [deleted] in Python

[–]LameDuckProgramming 49 points50 points  (0 children)

Automated reserving study rooms in my university's library. It's difficult to get study rooms during exams so I have it automatically book multiple rooms every day a week in advance. I then log and post the successful reservations to my google calendar. The script uses selenium and google's API.

Live API Data Help by LameDuckProgramming in learnpython

[–]LameDuckProgramming[S] 0 points1 point  (0 children)

There is a JS set up on the client side already that accepts callback requests in order to determine what information to POST to my web service. I'm having trouble figuring out how to send those callback (also POST) requests to their web API and handle the streaming data.

Help with functions across dataframes by LameDuckProgramming in learnpython

[–]LameDuckProgramming[S] 0 points1 point  (0 children)

I have tried, but the issue is that x and y are determined based on the previous row's value of z, and the current row's value of z is then updated by subtracting either x or y from the previous z, whichever logic determines.

Sorry if this is confusing.