Hi Reader, In case you missed it, I launched a free, 7-hour pandas course! 800+ students have enrolled, and a few have already earned their certificate of completion ๐ฉโ๐ ๐ Link of the weekโData Internshipsโ Looking for an internship in Data Science or Analytics? This site curates the latest internship postings and emails them to you each week! ๐ Tip #40: Build a DataFrame from multiple filesLetโs say that your dataset is spread across multiple files, but you want to read the dataset into a single pandas DataFrame. For example, I have a tiny dataset of stock market data in which each CSV file only includes a single day. Hereโs the first day: Hereโs the second day: And hereโs the third day: You could read each CSV file into its own DataFrame, combine them together, and then delete the original DataFrames, but that would be memory inefficient and require a lot of code. A better solution is to use Pythonโs built-in glob module: You can pass a pattern to the In this case, glob returns filenames in an arbitrary order, which is why we sorted the list using Pythonโs built-in We can then use a generator expression to read each of the files using Unfortunately, there are now duplicate values in the index. To avoid that, we can tell the Pretty cool, right? Need to build a DataFrame column-wise instead? Use the same code as above, except pass axis='columns' to ๐ Until next timeDid you like this weekโs tip? Please forward it to a friend or share this link in your favorite Slack team. It really helps me out! ๐ See you next Tuesday! - Kevin P.S. Would you wear pajamas during a Zoom call?โ Did someone AWESOME forward you this email? Sign up here to receive Data Science tips every week! |
Join 25,000+ aspiring Data Scientists and receive Python & Data Science tips every Tuesday!
Hi Reader, Next week, Iโll be offering a Black Friday sale on ALL of my courses. Iโll send you the details this Thursday! ๐จ ๐ Tip #50: What is a "method" in Python? In Python, a method is a function that can be used on an object because of the object's type. For example, if you create a Python list, the "append" method can be used on that list. All lists have an "append" method simply because they are lists: If you create a Python string, the "upper" method can be used on that string simply...
Hi Reader, I appreciate everyone who has emailed to check on me and my family post-Helene! It has been more than 6 weeks since the hurricane, and most homes in Asheville (mine included) still don't have clean, running water. We're hopeful that water service will return within the next month. In the meantime, we're grateful for all of the aid agencies providing free bottled water, free meals, places to shower, and so much more. โค๏ธ Thanks for allowing me to share a bit of my personal life with...
Hi Reader, Regardless of whether you enrolled, thanks for sticking with me through the launch of my new course! ๐ I've already started exploring topics for the next course... ๐ ๐ Link of the week git cheat sheet (PDF) A well-organized and highly readable cheat sheet from Julia Evans, the brilliant mind behind Wizard Zines! ๐ Tip #48: Three ways to set your environment variables in Python I was playing around with Mistral LLM this weekend (via LangChain in Python), and I needed to set an...