New answers tagged

2 votes
Accepted

Generate date_range for string intervals like 09:00-10:00/11:00-14:00/15:00-18:00 and calculate the working minutes

Consider revamping your current setup to work mostly in Pandas methods that operates on whole DataFrames and Series objects as opposed to mostly built-in Python methods on scalar values that loop and ...
user avatar
  • 815
2 votes

Generate date_range for string intervals like 09:00-10:00/11:00-14:00/15:00-18:00 and calculate the working minutes

Things that are good to stay in Spanish: your starting input file, your final output file. Everything else - your variable names, function names, comments, parameter names, and the column names of ...
user avatar
  • 47.9k
2 votes

Python script for Web scraping

When using Requests to fetch JSON content, it's usually more convenient to use the resonse.json() method instead of manually passing ...
user avatar
  • 2,538
0 votes

Optimise pandas code using def(x) and multiprocessing

Consider tightening up this code with the below tips. There may even be room to remove methods that do not seem required with sample of data. Maybe this is legacy code that needs updating. Source: ...
user avatar
  • 815
3 votes
Accepted

Create new columns based on existing columns

Don't loop. Pandas is designed to be vectorised, which means that 99% of the time when you imagine an operation to require a loop, that loop should be baked into some Numpy or Pandas call rather than ...
user avatar
  • 47.9k
5 votes

Create new columns based on existing columns

The content of the loop is of the form if condition: continue else: action() It would probably be easier to read as ...
user avatar
  • 57.7k
1 vote

Regex and pandas to read forecast sky condition string

You've landed in trouble with your indices again. I think the shape of your dataframe significantly mischaracterises what your data are actually saying: Per station, per station observation time, per ...
user avatar
  • 47.9k
2 votes
Accepted

Regex and pandas to read forecast sky condition string

At the start of get_sky_condition(), I don't see why you do a .str.strip() when defining ...
user avatar
2 votes
Accepted

Regex pattern matching to generate pandas multi index

indexs should be spelled indices. Your implementation is non-vectorised and should make use of the Pandas ...
user avatar
  • 47.9k
2 votes

Read a file format with mixed CSV and non-CSV content

While Reinderien posted an excellent solution to your problem. Let me take a closer look and give you some feedback on your code. Let us just focus on the 3 biggest things which stands out to me and ...
user avatar
2 votes

Read a file format with mixed CSV and non-CSV content

You're working too hard. You concatenate all of the CSV rows anyway, so LINES= has no value. Just read the CSV, and choose an easy way to identify invalid rows - ...
user avatar
  • 47.9k

Top 50 recent answers are included