{
  "source_file": "0930",
  "source_platform": "Medium",
  "author": "Federico Trotta",
  "title_listed": "Lists, Tuples, Dictionaries, And Data Frames in Python: The Complete Guide",
  "keywords": "Python,数据结构,Pandas",
  "domain": "数据处理",
  "content_type": "深度技术解析",
  "is_paid_flag": "部分免费/会员墙",
  "url": "https://towardsdatascience.com/lists-tuples-dictionaries-and-data-frames-in-python-the-complete-guide-7ab54d4819ee/",
  "publish_date": "2023-05",
  "corpus_stage": "预训练/SFT",
  "notes": "",
  "id": "d8f015b8f423",
  "collected_at": "2026-10-02T00:40:14",
  "title": "Lists, Tuples, Dictionaries, And Data Frames in Python: The Complete Guide | Towards Data Science",
  "body_markdown": "![Revisit consent button](https://cdn-cookieyes.com/assets/images/revisit.svg)\nWe value your privacy\nWe use cookies to enhance your browsing experience, serve personalised ads or content, and analyse our traffic. By clicking \"Accept All\", you consent to our use of cookies.\nCustomise Reject All Accept All\nCustomise Consent Preferences ![](https://cdn-cookieyes.com/assets/images/close.svg)\nWe use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.\nThe cookies that are categorised as \"Necessary\" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... Show more\nNecessaryAlways Active\nNecessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.\n  * Cookie\nBCTempID\n  * Duration\n10 minutes\n  * Description\nNo description available.\n\n\n  * Cookie\n__cf_bm\n  * Duration\n1 hour\n  * Description\nThis cookie, set by Cloudflare, is used to support Cloudflare Bot Management. \n\n\n  * Cookie\nAWSALBCORS\n  * Duration\n7 days\n  * Description\nAmazon Web Services set this cookie for load balancing.\n\n\n  * Cookie\n_cfuvid\n  * Duration\nsession\n  * Description\nCloudflare sets this cookie to track users across sessions to optimize user experience by maintaining session consistency and providing personalized services\n\n\n  * Cookie\nli_gc\n  * Duration\n6 months\n  * Description\nLinkedin set this cookie for storing visitor's consent regarding using cookies for non-essential purposes.\n\n\n  * Cookie\n__hssrc\n  * Duration\nsession\n  * Description\nThis cookie is set by Hubspot whenever it changes the session cookie. The __hssrc cookie set to 1 indicates that the user has restarted the browser, and if the cookie does not exist, it is assumed to be a new session.\n\n\n  * Cookie\n__hssc\n  * Duration\n1 hour\n  * Description\nHubSpot sets this cookie to keep track of sessions and to determine if HubSpot should increment the session number and timestamps in the __hstc cookie.\n\n\n  * Cookie\nwpEmojiSettingsSupports\n  * Duration\nsession\n  * Description\nWordPress sets this cookie when a user interacts with emojis on a WordPress site. It helps determine if the user's browser can display emojis properly.\n\n\n  * Cookie\nBCSessionID\n  * Duration\n1 year 1 month 4 days\n  * Description\nBlueconic sets this cookie as a unique identifier for the BlueConic profile.\n\n\n  * Cookie\n_octo\n  * Duration\n1 year\n  * Description\nNo description available.\n\n\n  * Cookie\nlogged_in\n  * Duration\n1 year\n  * Description\nNo description available.\n\n\n  * Cookie\n__Secure-YEC\n  * Duration\npast\n  * Description\nYouTube sets this cookie to stores the user's video player preferences using embedded YouTube video\n\n\n  * Cookie\n__eoi\n  * Duration\n6 months\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nAWSALBTGCORS\n  * Duration\n7 days\n  * Description\nNo description available.\n\n\n  * Cookie\nlogin-status-p\n  * Duration\npast\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nAWSALBTG\n  * Duration\n7 days\n  * Description\nNo description available.\n\n\n  * Cookie\ncsrf_token\n  * Duration\nsession\n  * Description\nNo description available.\n\n\n  * Cookie\ntoken_v2\n  * Duration\n1 day\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nD\n  * Duration\n1 year\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nPHPSESSID\n  * Duration\nsession\n  * Description\nThis cookie is native to PHP applications. The cookie stores and identifies a user's unique session ID to manage user sessions on the website. The cookie is a session cookie and will be deleted when all the browser windows are closed.\n\n\n  * Cookie\nVISITOR_PRIVACY_METADATA\n  * Duration\n6 months\n  * Description\nYouTube sets this cookie to store the user's cookie consent state for the current domain. \n\n\n  * Cookie\ncookietest\n  * Duration\nsession\n  * Description\nThe cookietest cookie is typically used to determine whether the user's browser accepts cookies, essential for website functionality and user experience.\n\n\n  * Cookie\n__Host-airtable-session\n  * Duration\n1 year\n  * Description\nThis cookie is used to enable us to integrate the services of Airtable.\n\n\n  * Cookie\n__Host-airtable-session.sig\n  * Duration\n1 year\n  * Description\nThis cookie is used to enable us to integrate the services of Airtable.\n\n\n  * Cookie\nm\n  * Duration\n1 year 1 month 4 days\n  * Description\nStripe sets this cookie for fraud prevention purposes. It identifies the device used to access the website, allowing the website to be formatted accordingly.\n\n\n  * Cookie\nBIGipServer*\n  * Duration\nsession\n  * Description\nMarketo sets this cookie to collect information about the user's online activity and build a profile about their interests to provide advertisements relevant to the user. \n\n\n  * Cookie\n__cfruid\n  * Duration\nsession\n  * Description\nCloudflare sets this cookie to identify trusted web traffic.\n\n\n  * Cookie\n_GRECAPTCHA\n  * Duration\n6 months\n  * Description\nGoogle Recaptcha service sets this cookie to identify bots to protect the website against malicious spam attacks.\n\n\n  * Cookie\n__Secure-YNID\n  * Duration\n6 months\n  * Description\nGoogle cookie used to protect user security and prevent fraud, especially during the login process.\n\n\n  * Cookie\ncookieyes-consent\n  * Duration\n1 year\n  * Description\nCookieYes sets this cookie to remember users' consent preferences so that their preferences are respected on subsequent visits to this site. It does not collect or store any personal information about the site visitors.\n\n\nFunctional\nFunctional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.\n  * Cookie\nlidc\n  * Duration\n1 day\n  * Description\nLinkedIn sets the lidc cookie to facilitate data center selection.\n\n\n  * Cookie\nbrw\n  * Duration\n1 year\n  * Description\nNo description available.\n\n\n  * Cookie\nbrwConsent\n  * Duration\n5 minutes\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nWMF-Uniq\n  * Duration\n1 year\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nloom_anon_comment\n  * Duration\n1 year\n  * Description\nNo description available.\n\n\n  * Cookie\nloom_referral_video\n  * Duration\nsession\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nVISITOR_INFO1_LIVE\n  * Duration\n6 months\n  * Description\nA cookie set by YouTube to measure bandwidth that determines whether the user gets the new or old player interface.\n\n\n  * Cookie\nyt-remote-connected-devices\n  * Duration\nNever Expires\n  * Description\nYouTube sets this cookie to store the user's video preferences using embedded YouTube videos.\n\n\n  * Cookie\nytidb::LAST_RESULT_ENTRY_KEY\n  * Duration\nNever Expires\n  * Description\nThe cookie ytidb::LAST_RESULT_ENTRY_KEY is used by YouTube to store the last search result entry that was clicked by the user. This information is used to improve the user experience by providing more relevant search results in the future.\n\n\n  * Cookie\nyt-remote-device-id\n  * Duration\nNever Expires\n  * Description\nYouTube sets this cookie to store the user's video preferences using embedded YouTube videos.\n\n\n  * Cookie\nyt-remote-session-name\n  * Duration\nsession\n  * Description\nThe yt-remote-session-name cookie is used by YouTube to store the user's video player preferences using embedded YouTube video.\n\n\n  * Cookie\nyt-remote-fast-check-period\n  * Duration\nsession\n  * Description\nThe yt-remote-fast-check-period cookie is used by YouTube to store the user's video player preferences for embedded YouTube videos.\n\n\n  * Cookie\nyt-remote-session-app\n  * Duration\nsession\n  * Description\nThe yt-remote-session-app cookie is used by YouTube to store user preferences and information about the interface of the embedded YouTube video player.\n\n\n  * Cookie\nyt-remote-cast-available\n  * Duration\nsession\n  * Description\nThe yt-remote-cast-available cookie is used to store the user's preferences regarding whether casting is available on their YouTube video player.\n\n\n  * Cookie\nyt-remote-cast-installed\n  * Duration\nsession\n  * Description\nThe yt-remote-cast-installed cookie is used to store the user's video player preferences using embedded YouTube video.\n\n\n  * Cookie\ncp_session\n  * Duration\n3 months\n  * Description\nCodepen sets this cookie for Help systems found in the website.\n\n\n  * Cookie\nloid\n  * Duration\n1 year 1 month 4 days\n  * Description\nThis cookie is set by the Reddit. The cookie enables the sharing of content from the website onto the social media platform.\n\n\nAnalytics\nAnalytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.\n  * Cookie\n__hstc\n  * Duration\n6 months\n  * Description\nHubspot set this main cookie for tracking visitors. It contains the domain, initial timestamp (first visit), last timestamp (last visit), current timestamp (this visit), and session number (increments for each subsequent session).\n\n\n  * Cookie\nhubspotutk\n  * Duration\n6 months\n  * Description\nHubSpot sets this cookie to keep track of the visitors to the website. This cookie is passed to HubSpot on form submission and used when deduplicating contacts.\n\n\n  * Cookie\n_ga\n  * Duration\n1 year 1 month 4 days\n  * Description\nGoogle Analytics sets this cookie to calculate visitor, session and campaign data and track site usage for the site's analytics report. The cookie stores information anonymously and assigns a randomly generated number to recognise unique visitors.\n\n\n  * Cookie\n_ga_*\n  * Duration\n1 year 1 month 4 days\n  * Description\nGoogle Analytics sets this cookie to store and count page views.\n\n\n  * Cookie\n__Host-psifi.analyticsTrace\n  * Duration\n6 hours\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\n__Host-psifi.analyticsTraceV2\n  * Duration\n6 hours\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\n_gh_sess\n  * Duration\nsession\n  * Description\nGitHub sets this cookie for temporary application and framework state between pages like what step the user is on in a multiple step form.\n\n\n  * Cookie\nYSC\n  * Duration\nsession\n  * Description\nYSC cookie is set by Youtube and is used to track the views of embedded videos on Youtube pages.\n\n\n  * Cookie\najs_anonymous_id\n  * Duration\n1 year\n  * Description\nThis cookie is set by Segment to count the number of people who visit a certain site by tracking if they have visited before.\n\n\n  * Cookie\nvuid\n  * Duration\n1 year 1 month 4 days\n  * Description\nVimeo installs this cookie to collect tracking information by setting a unique ID to embed videos on the website. \n\n\nPerformance\nPerformance cookies are used to understand and analyse the key performance indexes of the website which helps in delivering a better user experience for the visitors.\n  * Cookie\nAWSALB\n  * Duration\n7 days\n  * Description\nAWSALB is an application load balancer cookie set by Amazon Web Services to map the session to the target.\n\n\n  * Cookie\nacq\n  * Duration\npast\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nacq.sig\n  * Duration\npast\n  * Description\nDescription is currently not available.\n\n\n  * Cookie\nptc\n  * Duration\n2 years\n  * Description\nNo description available.\n\n\nAdvertisement\nAdvertisement cookies are used to provide visitors with customised advertisements based on the pages you visited previously and to analyse the effectiveness of the ad campaigns.\n  * Cookie\nmuc_ads\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to collect user behaviour and interaction data to optimize the website.\n\n\n  * Cookie\nguest_id_marketing\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to identify and track the website visitor.\n\n\n  * Cookie\nguest_id_ads\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to identify and track the website visitor.\n\n\n  * Cookie\npersonalization_id\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to integrate and share features for social media and also store information about how the user uses the website, for tracking and targeting.\n\n\n  * Cookie\nguest_id\n  * Duration\n1 year 1 month 4 days\n  * Description\nTwitter sets this cookie to identify and track the website visitor. It registers if a user is signed in to the Twitter platform and collects information about ad preferences.\n\n\n  * Cookie\nbcookie\n  * Duration\n1 year\n  * Description\nLinkedIn sets this cookie from LinkedIn share buttons and ad tags to recognize browser IDs.\n\n\n  * Cookie\n__Secure-ROLLOUT_TOKEN\n  * Duration\n6 months\n  * Description\nYouTube sets this cookie to manage feature rollout and experimentation. It helps Google control which new features or interface changes are shown to users as part of testing and staged rollouts, ensuring consistent experience for a given user during an experiment.\n\n\n  * Cookie\nyt.innertube::nextId\n  * Duration\nNever Expires\n  * Description\nYouTube sets this cookie to register a unique ID to store data on what videos from YouTube the user has seen.\n\n\n  * Cookie\nyt.innertube::requests\n  * Duration\nNever Expires\n  * Description\nYouTube sets this cookie to register a unique ID to store data on what videos from YouTube the user has seen.\n\n\n  * Cookie\nsession_tracker\n  * Duration\nsession\n  * Description\nThis cookie is set by the Reddit. This cookie is used to identify trusted web traffic. It also helps in adverstising on the website.\n\n\n  * Cookie\nedgebucket\n  * Duration\nsession\n  * Description\nReddit sets this cookie to save the information about a log-on Reddit user, for the purpose of advertisement recommendations and updating the content.\n\n\n  * Cookie\ndid\n  * Duration\n1 year\n  * Description\nArbor sets this cookie to show targeted ads to site visitors.This cookie expires after 2 months or 1 year.\n\n\nUncategorised\nOther uncategorised cookies are those that are being analysed and have not been classified into a category as yet.\nNo cookies to display.\nReject All Save My Preferences Accept All\nToggle Search[](https://towardsdatascience.com/)Toggle Mobile Navigation\n[](https://towardsdatascience.com/)\nPublish AI, ML & data-science insights to a global community of data professionals.\nSign in[Submit an Article](https://write.insightmediagroup.io)\n[Latest](https://towardsdatascience.com/latest/)[Editor's Picks](https://towardsdatascience.com/tag/editors-pick/)[Newsletter](https://towardsdatascience.com/tag/the-variable/)[ShipAI](https://towardsdatascience.com/shipai/)\n* * *\n[Write For TDS](https://towardsdatascience.com/submissions/)\n[LinkedIn](https://www.linkedin.com/company/towards-data-science/)[X](https://x.com/TDataScience)Toggle Search\n[Data Science](https://towardsdatascience.com/category/data-science/)\n# Lists, Tuples, Dictionaries, And Data Frames in Python: The Complete Guide\nAll you need to know to master the most used data structures in Python\n[Federico Trotta](https://towardsdatascience.com/author/federicotrotta/)\nMay 24, 202317 min read\n![Image by Pexels on Pixabay](https://assets.insightmediagroup.io/media/wp-content/uploads/2023/05/132atRC8027o3BkGPCgP1Yg.jpeg)\nImage by [Pexels](https://pixabay.com/it/users/pexels-2286921/?utm_source=link-attribution&utm_medium=referral&utm_campaign=image&utm_content=1284475) on [Pixabay](https://pixabay.com/it//?utm_source=link-attribution&utm_medium=referral&utm_campaign=image&utm_content=1284475)\nIf you've started learning Python, whether you want to be a Software Engineer or a Data Scientist, you absolutely need to master data structures.\nPython has a lot of data structures that allow us to store data. In this article, we'll dive into the most used ones. So, if you're starting your career and need to learn data structures, then this article is definitely for you.\nHere's what you'll find here:\ntext\n\n```\nTable of Contents:\n\nLists\n  Definitions and creation examples\n  Lists manipulation\n  List comprehension\n  List of lists\nTuples\nDictionaries\n  Dictionaries manipulation\n  Nested dictionaries\n  Dictionary comprehension\nData frames\n   Basic data frames manipulations with Pandas\n```\n\n* * *\nLearn this step by step with the interactive [AI and Data Scientist](https://roadmap.sh/ai-data-scientist), [Computer Science](https://roadmap.sh/computer-science) and [Machine Learning](https://roadmap.sh/machine-learning) roadmaps.\n## Lists\n### Definition and creation examples\nIn Python, a list is a collection of ordered elements that can be of any type: strings, integers, floats, etc...\nTo create a list, the items must be inserted between square brackets and separated by a comma. For example, here's how we can create a list of integers:\npython\n\n```\n# Create list of integers\nmy_integers = [1, 2, 3, 4, 5, 6]\n```\n\nBut lists can also have \"mixed\" types stored inside them. For example, let's create a list with both integers and strings:\npython\n\n```\n# Create a mixed list\nmixed_list = [1, 3, \"dad\", 101, \"apple\"]\n```\n\nTo create a list, we can also use the Python built-in function `list()`. This is how we can use it:\npython\n\n```\n# Create list and print it\nmy_list = list((1, 2, 3, 4, 5))\nprint(my_list)\n\n>>>  \n\n    [1, 2, 3, 4, 5]\n```\n\nThis built-in function is very useful in some particular cases. For example, let's say we want to create a list of numbers in the range (1–10). Here's how we can do so:\npython\n\n```\n# Create a list in a range\nmy_list = list(range(1, 10))\nprint(my_list)\n\n>>>\n\n  [1, 2, 3, 4, 5, 6, 7, 8, 9]\n```\n\ntext\n\n```\nNOTE:\n\nRemember that the built-in function \"range\" includes the first value,\nand excludes the last one.\n```\n\nNow, let's see how we can manipulate lists.\n### Lists manipulation\nThanks to the fact that lists are mutable, we have lots of possibilities to manipulate them. For example, let's say we have a list of names, but we made a mistake and we want to change one. Here's how we can do so:\npython\n\n```\n# List of names\nnames = [\"James\", \"Richard\", \"Simon\", \"Elizabeth\", \"Tricia\"]\n# Change the wrong name\nnames[0] = \"Alexander\"\n# Print list\nprint(names)\n\n>>>\n\n    ['Alexander', 'Richard', 'Simon', 'Elizabeth', 'Tricia']\n```\n\nSo, in the above example, we've changed the first name of the list from James to Alexander.\ntext\n\n```\nNOTE:\n\nIn case you didn't know, note that in Python the first element\nis always accessed by \"0\", regarding of the type we're manipulating.\nSo, in the above example, \"names[0]\" represents the first element\nof the list \"names\".\n```\n\nNow, suppose we've forgotten a name. We can add it to our list like so:\npython\n\n```\n# List of names\nnames = [\"James\", \"Richard\", \"Simon\", \"Elizabeth\", \"Tricia\"]\n# Append another name\nnames.append(\"Alexander\")\n# Print list\nprint(names) \n\n>>>\n\n    ['James', 'Richard', 'Simon', 'Elizabeth', 'Tricia', 'Alexander']\n```\n\nIf we need to concatenate two lists, we have two possibilities: the `concatenate` method or the `extend()`one. Let's see them:\npython\n\n```\n# Create list1\nlist1 = [1, 2, 3]\n# Create list2\nlist2 = [4, 5, 6]\n# Concatenate lists\nconcatenated_list = list1 + list2\n# Print concatenated list\nprint(concatenated_list)\n\n>>>\n\n  [1, 2, 3, 4, 5, 6]\n```\n\nSo, this method creates a list that is the sum of other lists. Let's see the `extend()` method:\npython\n\n```\n# Create list1\nlist1 = [1, 2, 3]\n# Create list2\nlist2 = [4, 5, 6]\n# Extend list1 with list2\nlist1.extend(list2)\n# Print new list1\nprint(list1)\n\n>>>\n\n  [1, 2, 3, 4, 5, 6]\n```\n\nAs we can see, the results are the same, but the syntax is different. This method extends `list1` with `list2`.\nIf we want to remove elements, we have two possibilities: we can use the `remove()` method or `del`. Let's see them:\npython\n\n```\n# Create list\nmy_list = [1, 2, 3, 'four', 5.0]\n# Remove one element and print\nmy_list.remove('four')\nprint(my_list)\n\n>>>\n\n  [1, 2, 3, 5.0]\n```\n\nLet's see the other method:\npython\n\n```\n# Create list\nmy_list = [1, 2, 3, 'four', 5.0]\n# Delete one element and print\ndel my_list[3]\nprint(my_list)\n\n>>>\n\n    [1, 2, 3, 5.0]\n```\n\nSo, we get the same results with both methods, but `remove()` gives us the possibility to explicitly write the element to remove, while `del` needs to access the position of the element of the list.\ntext\n\n```\nNOTE:\n\nIf you've gained familiarity with accessing positions, in the above\nexample my_list[3] = 'four'. Because, remember: in Python we start counting\npositions from 0.\n```\n\n### List comprehension\nThere are a lot of cases where we need to create lists starting from existing lists, generally applying some filters to the existing data. To do so, we have two possibilities:\n  1. We use loops and statements.\n  2. We use list comprehension.\n\n\nPractically, they are both the same way to write the same thing, but list comprehension is more concise and elegant.\nBut before we discuss these methods, you may need a deep overview of loops and statements. Here are a couple of articles I wrote in the past that may help you:\n> [**Loops and statements in Python: A deep understanding (with examples)**](https://towardsdatascience.com/loops-and-statements-in-python-a-deep-understanding-with-examples-2099fc6e37d7)\n> [**Python Loops: A Complete Guide On How To Iterate in Python**](https://towardsdatascience.com/python-loops-a-complete-guide-on-how-to-iterate-in-python-b29e0d12211d)\nNow, let's see a couple of examples using loops and statements directly.\nSuppose we have a shopping list. We want our program to print that we love one fruit and that we don't like the others on the list. Here's how we can do so:\npython\n\n```\n# Create shopping list\nshopping_list = [\"banana\", \"apple\", \"orange\", \"lemon\"]\n# Print the one I like\nfor fruit in shopping_list:\n    if fruit == \"lemon\":\n        print(f\"I love {fruit}\")\n    else:\n        print(f\"I don't like {fruit}\")\n\n>>>\n\n    I don't like banana\n    I don't like apple\n    I don't like orange\n    I love lemon\n```\n\nAnother example could be the following. Suppose we have a list of numbers and we want to print just the even ones. Here's how we can do so:\npython\n\n```\n# Create list\nnumbers = [1,2,3,4,5,6,7,8]\n# Create empty list\neven_list = []\n# Print even numbers\nfor even in numbers:\n    if even %2 == 0:\n        even_list.append(even)\n    else:\n        pass\n\nprint(even_list)\n\n>>>\n\n    [2, 4, 6, 8]\n```\n\ntext\n\n```\nNOTE:\n\nIf you are not familiar with the sintax %2 == 0 it means that we are\ndividing a number by 2 and expect a reminder of 0. In other words,\nwe are asking our program to intercept the even numbers.\n```\n\nSo, in the above example, we've created a list of numbers. Then, we've created an empty list that is used after the loop to append all the even numbers. This way, we've created a list of even numbers from a list with \"general\" numbers.\nNow... this way of creating new lists with loops and statements is a little \"heavy\". I mean: it requires a lot of code. We can gain the same results in a more concise way using list comprehension.\nFor example, to create a list with even numbers we can use list comprehension like so:\npython\n\n```\n# Create list\nnumbers = [1,2,3,4,5,6,7,8]\n# Create list of even numbers\neven_numbers = [even for even in numbers if even %2 == 0]\n# Print even list\nprint(even_numbers)\n\n>>>\n\n    [2, 4, 6, 8]\n```\n\nSo, list comprehension creates directly a new list and we define the condition inside it. As we can see, we gain the same result as before, but in just one line of code: not bad!\nNow, let's create a list with comments on the fruit I love (and the fruit I don't) with list comprehension:\npython\n\n```\n# Create shipping list\nshopping_list = [\"banana\", \"apple\", \"orange\", \"lemon\"]\n# Create commented list and print it\ncommented_list = [f\"I love {fruit}\" if fruit == \"banana\"\n                  else f\"I don't like {fruit}\"\n                  for fruit in shopping_list]\nprint(commented_list)\n\n>>>\n\n  ['I love banana', \"I don't like apple\", \"I don't like orange\",\n   \"I don't like lemon\"]\n```\n\nSo, we gained the same result as before, but with just a line of code. The only difference is that here we've printed a list (because list comprehension creates one!), while before we just printed the results.\n### List of lists\nThere is also the possibility to create lists of lists, that are lists nested into one list. This possibility is useful when we want to represent listed data as a unique list.\nFor example, consider we want to create a list of students and their grades. We could create something like that:\npython\n\n```\n# Create lis with students and their grades\nstudents = [\n    [\"John\", [85, 92, 78, 90]],\n    [\"Emily\", [77, 80, 85, 88]],\n    [\"Michael\", [90, 92, 88, 94]],\n    [\"Sophia\", [85, 90, 92, 87]]\n]\n```\n\nThis is a useful notation if, for example, we want to calculate the mean grade for each student. We can do it like so:\npython\n\n```\n# Iterate over the list\nfor student in students:\n    name = student[0] # Access names\n    grades = student[1] # Access grades\n    average_grade = sum(grades) / len(grades) # Calculate mean grades\n    print(f\"{name}'s average grade is {average_grade:.2f}\")\n\n>>>\n\n    John's average grade is 86.25\n    Emily's average grade is 82.50\n    Michael's average grade is 91.00\n    Sophia's average grade is 88.50\n```\n\n## Tuples\nTuples are another data structure type in Python. They are defined with round brackets and, as lists, can contain any data type separated by a comma. So, for example, we can define a tuple like so:\npython\n\n```\n# Define a tuple and print it\nmy_tuple = (1, 3.0, \"John\")\nprint(my_tuple)\n\n>>>\n\n    (1, 3.0, 'John')\n```\n\nThe difference between a tuple and a list is that a tuple is **immutable**. This means that the elements of a tuple can not be changed. So, for example, if we try to append a value to a tuple we get an error:\npython\n\n```\n# Create a tuple with names\nnames = (\"James\", \"Jhon\", \"Elizabeth\")\n# Try to append a name\nnames.append(\"Liza\")\n\n>>>\n\n    AttributeError: 'tuple' object has no attribute 'append'\n```\n\nSo, since we can't modify tuples, they are useful when we want our data to be immutable; for example, in situations where we don't want to make mistakes.\nA practical example may be the cart of an e-commerce. We may want this kind of data to be immutable so that we don't make any mistakes when manipulating it. Imagine someone bought a shirt, a pair of shoes, and a watch from our e-commerce. We may report this data with quantity and price into one tuple:\npython\n\n```\n# Create a chart as a tuple\ncart = (\n    (\"Shirt\", 2, 19.99),\n    (\"Shoes\", 1, 59.99),\n    (\"Watch\", 1, 99.99)\n)\n```\n\nOf course, to be precise, this is a tuple of tuples.\nSince tuples are immutable, they are more efficient in terms of performance, meaning they save our computer's resources. But when it comes to manipulation, we can use the exact same code as we've seen for lists, so we won't write it again.\nFinally, similarly to lists, we can create a tuple with the built-in function `tuple()` like so:\npython\n\n```\n# Create a tuple in a range\nmy_tuple = tuple(range(1, 10))\nprint(my_tuple)\n\n>>>\n\n  (1, 2, 3, 4, 5, 6, 7, 8, 9)\n```\n\n## Dictionaries\nA dictionary is a way to store data that are coupled as keys and values. This is how we can create one:\npython\n\n```\n# Create a dictionary\nmy_dictionary = {'key_1':'value_1', 'key_2':'value_2'}\n```\n\nSo, we create a dictionary with curly brackets and we store in it a couple of keys and values separated by a colon. The couples keys-values are then separated by a comma.\nNow, let's see how we can manipulate dictionaries.\n### Dictionaries manipulation\nBoth keys and values of a dictionary can be of any type: strings, integers, or floats. So, for example, we can create a dictionary like so:\npython\n\n```\n# Create a dictionary of numbers and print it\nnumbers = {1:'one', 2:'two', 3:'three'}\nprint(numbers)\n\n>>>\n\n    {1: 'one', 2: 'two', 3: 'three'}\n```\n\nBut we can create one also like that:\npython\n\n```\n# Create a dictionary of numbers and print it\nnumbers = {'one':1, 'two':2.0, 3:'three'}\nprint(numbers)\n\n>>>\n\n  {'one': 1, 'two': 2.0, 3: 'three'}\n```\n\nChoosing the type for values and keys depends on the problem we need to solve. Anyway, considering the dictionary we've seen before, we can access both values and keys like so:\npython\n\n```\n# Access values and keys\nkeys = list(numbers.keys())\nvalues = tuple(numbers.values())\n# Print values and keys\nprint(f\"The keys are: {keys}\")\nprint(f\"The values are: {values}\")\n\n>>>\n\n    The keys are: ['one', 'two', 3]\n    The values are: (1, 2.0, 'three')\n```\n\nSo, if our dictionary is called `numbers` we access its key with `numbers.keys()`. And with `numbers.values()` we access its values. Also, note that we have created a list with the keys and a tuple with the values using the notation we've seen before.\nOf course, we can also iterate over dictionaries. For example, suppose we want to print the values that are greater than a certain threshold:\npython\n\n```\n# Create a shopping list with fruits and prices\nshopping_list = {'banana':2, 'apple':1, 'orange':1.5}\n# Iterate over the values\nfor values in shopping_list.values():\n    # Values greater than threshold\n    if values > 1:\n        print(values)\n\n>>>\n\n    2\n    1.5\n```\n\nLike lists, dictionaries are mutable. So, if we want to add a value to a dictionary we have to define the key and the value to add to it. We can do it like so:\npython\n\n```\n# Create the dictionary\nperson = {'name': 'John', 'age': 30}\n# Add value and key and print\nperson['city'] = 'New York'\nprint(person)\n\n>>>\n\n    {'name': 'John', 'age': 30, 'city': 'New York'}\n```\n\nTo modify a value of a dictionary, we need to access its key:\npython\n\n```\n# Create a dictionary\nperson = {'name': 'John', 'age': 30}\n# Change age value and print\nperson['age'] = 35\nprint(person)\n\n>>>\n\n    {'name': 'John', 'age': 35}\n```\n\nTo delete a pair key-value from a dictionary, we need to access its key:\npython\n\n```\n# Create dictionary\nperson = {'name': 'John', 'age': 30}\n# Delete age and print\ndel person['age']\nprint(person)\n\n>>>\n\n    {'name': 'John'}\n```\n\n### Nested dictionaries\nWe have seen before that we can create lists of lists and tuples of tuples. Similarly, we can create nested dictionaries. Suppose, for example, we want to create a dictionary to store the data related to a class of students. We can do it like so:\npython\n\n```\n# Create a classroom dictionary\nclassroom = {\n    'student_1': {\n        'name': 'Alice',\n        'age': 15,\n        'grades': [90, 85, 92]\n    },\n    'student_2': {\n        'name': 'Bob',\n        'age': 16,\n        'grades': [80, 75, 88]\n    },\n    'student_3': {\n        'name': 'Charlie',\n        'age': 14,\n        'grades': [95, 92, 98]\n    }\n```\n\nSo, the data of each student are represented as a dictionary and all the dictionaries are stored in a unique dictionary, representing the classroom. As we can see, the values of a dictionary can even be lists (or tuples, if we'd like). In this case, we've used lists to store the grades of each student.\nTo print the values of one student, we just need to remember that, from the perspective of the classroom dictionary, we need to access the key and, in this case, the keys are the students themselves. This means we can do it like so:\npython\n\n```\n# Access student_3 and print\nstudent_3 = classroom['student_3']\nprint(student_3)\n\n>>>\n\n    {'name': 'Charlie', 'age': 14, 'grades': [95, 92, 98]}\n```\n\n### Dictionaries comprehension\nDictionary comprehension allows us to create dictionaries concisely and efficiently. It's similar to list comprehension but, instead of creating a list, it creates a dictionary.\nSuppose we have a dictionary where we have stored some objects and their prices. We want to know the objects that cost less than a certain threshold. We can do it like so:\npython\n\n```\n# Define initial dictionary\nproducts = {'shoes': 100, 'watch': 50, 'smartphone': 250, 'tablet': 120}\n# Define threshold\nmax_price = 150\n# Filter for threshold\nproducts_to_buy = {fruit: price for fruit, price in products.items() if price <= max_price}\n# Print filtered dictionary\nprint(products_to_buy)\n\n>>>\n\n    {'shoes': 100, 'watch': 50, 'tablet': 120}\n```\n\nSo, the syntax to use dictionary comprehension is:\npython\n\n```\nnew_dict = {key:value for key, value in iterable}\n```\n\nWhere iterable is any iterable Python object. It can be a list, a tuple, another dictionary, etc...\nCreating dictionaries with the \"standard\" method would require a lot of code, with conditions, loops, and statements. Instead, as we can see, dictionary comprehension allows us to create a dictionary, based on conditions, with just one line of code.\nDictionary comprehension is especially useful when we need to create a dictionary retrieving data from other sources or data structures. For example, say we need to create a dictionary retrieving values from two lists. We can do it like so:\npython\n\n```\n# Define names and ages in lists\nnames = ['John', 'Jane', 'Bob', 'Alice']\ncities = ['New York', 'Boston', 'London', 'Rome']\n# Create dictionary from lists and print results\nname_age_dict = {name: city for name, city in zip(names, cities)}\nprint(name_age_dict)\n\n>>>\n\n   {'John': 'New York', 'Jane': 'Boston', 'Bob': 'London', 'Alice': 'Rome'}\n```\n\n## Data frames\n![A data frame is the representation of tabular data. Image from the Panda&#039;s website here: https://pandas.pydata.org/docs/getting_started/index.html](https://assets.insightmediagroup.io/media/wp-content/uploads/2023/05/1ktO7pYF7T7GyzKZnmHa80w.jpeg)\nA data frame is the representation of tabular data. Image from the Panda's website here: <https://pandas.pydata.org/docs/getting_started/index.html>\nA data frame is a two-dimensional data structure consisting of columns and rows. So, it is somehow similar to a spreadsheet or a table in an SQL database. They have the following characteristics:\n  1. Each row represents an individual observation or record.\n  2. Each column represents a variable or a specific attribute of the data.\n  3. They have labeled rows (called indexes) and columns, making it easy to manipulate the data.\n  4. The columns can contain different types of data, like integers, strings, or floats. Even a single column can contain different data types.\n\n\nWhile data frames are the typical data structure used in the context of Data Analysis and Data Science, it is not uncommon that a Python Software Engineer may need to manipulate a data frame, and this is why we're having an overview of data frames.\nHere's how a data frame appears:\n![A data frame. Image by Federico Trotta.](https://assets.insightmediagroup.io/media/wp-content/uploads/2023/05/1jlh4l3iTHFc7Klh4Tc2_JQ.png)\nA data frame. Image by Federico Trotta.\nSo, on the left (in the blue rectangle) we can see the indexes, meaning the row counts. We can then see that a data frame can contain different types of data. In particular, the column \"Age\" contains different data types (one string and two integers).\n### Basic data frames manipulation with Pandas\nWhile recently a new library to manipulate data frames called \"Polars\" started circulating, here we'll see some data manipulation with Pandas which is still the most used as of today.\nFirst of all, generally, we can create data frames by importing data from `.xlsx` or `.cvs` files. In Pandas we can do it like so:\npython\n\n```\nimport pandas as pd\n\n# Import cvs file\nmy_dataframe = pd.read_csv('a_file.csv')\n\n# Import xlsx\nmy_dataframe_2 = pd.read_excel('a_file_2.xlsx')\n```\n\nIf we want to create a data frame:\npython\n\n```\nimport pandas as pd\n\n# Create a dictionary with different types of data\ndata = {\n    'Name': ['John', 'Alice', 'Bob'],\n    'Age': ['twenty-five', 30, 27],\n    'City': ['New York', 'London', 'Sydney'],\n    'Salary': [50000, 60000.50, 45000.75],\n    'Is_Employed': [True, True, False]\n}\n\n# Create the dataframe\ndf = pd.DataFrame(data)\n```\n\nThis is the data frame we've shown above. So, as we can see, we first create a dictionary, and then we convert it to a data frame with the method `pd.DataFrame()`.\nWe have three possibilities to visualize a data frame. Suppose we have a data frame called `df`:\n  1. The first one is `print(df)`.\n  2. The second one is `df.head()` that will show the first 5 rows of our data frame. In case we have a data frame with a lot of rows, we can show more than the first five. For example, `df.head(20)` shows the first 20.\n  3. The third one is `df.tail()` that works exactly like `head()`, but this shows the last rows.\n\n\nOn the side of visualization, using the above `df`, this is what `df.head()` shows:\n![What df.head\\(\\) shows. Image by Federico Trotta.](https://assets.insightmediagroup.io/media/wp-content/uploads/2023/05/1ypgHf93Txw6oOwUPwuLGew.png)\nWhat df.head() shows. Image by Federico Trotta.\nAnd this is what `print(df)` shows:\n![What print\\(df\\) shows. Image by Federico Trotta.](https://assets.insightmediagroup.io/media/wp-content/uploads/2023/05/1o5rKF43Mba8o_GPgPL9pHw.png)\nWhat print(df) shows. Image by Federico Trotta.\nIn the case of small data sets like this one, the difference is only a matter of taste (I prefer `head()` because it \"shows the tabularity\" of data). But in the case of large data sets, `head()` is way much better. Try it, and let me know!\nConsider that Pandas is a very wide library, meaning it allows us to manipulate tabular data in a variety of ways, so it'd need to be treated alone. Here we want to show just the very basics, so we'll see how we can add and delete a column (the columns of a data frame are also called \"Pandas series\").\nSuppose we want to add a column to the data frame `df` we've seen above that is telling us if people are married or not. We can do it like so:\nbash\n\n```\n# Add marital status\ndf[\"married\"] = [\"yes\", \"yes\", \"no\"]\n```\n\ntext\n\n```\nNOTE:\n\nthis is the same notation we used to add values to a dictionary.\nReturn back on the article and compare the two methods.\n```\n\nAnd showing the head we have:\n![The data frame df with the marital status. Image by Federico Trotta.](https://assets.insightmediagroup.io/media/wp-content/uploads/2023/05/1CaEn3BWt4M5-4Ci4C0zOVQ.png)\nThe data frame df with the marital status. Image by Federico Trotta.\nTo delete one column:\npython\n\n```\n# Delete the \"Is_Employed\" column\ndf = df.drop('Is_Employed', axis=1)\n```\n\nAnd we get:\n![The data frame without the column related to employment data. Image by Federico Trotta.](https://assets.insightmediagroup.io/media/wp-content/uploads/2023/05/1JCgn0p7knJWMqtqcUovUxg.png)\nThe data frame without the column related to employment data. Image by Federico Trotta.\nNote that we need to use `axis=1` because here we are telling Pandas to remove columns and since a data frame is a two-dimensional data structure, `axis=1` represents the vertical direction.\nInstead, if we want to drop a row, we need to use `axis=0`. For example, suppose we want to delete the row associated with the index 1 ( that is the second row because, again, we start counting from 0):\npython\n\n```\n# Delete the second row \ndf = df.drop(1, axis=0)\n```\n\nAnd we get:\n![The data frame without the second row. Image by Federico Trotta.](https://assets.insightmediagroup.io/media/wp-content/uploads/2023/05/1jFWAyKYpBesDMjiLEUxqyQ.png)\nThe data frame without the second row. Image by Federico Trotta.\n## Conclusions\nSo far, we've seen the most used data structures in Python. These are not the only ones, but surely the most used.\nAlso, there is no right or wrong in using one rather than another: we just need to understand what data we need to store and use the best data structure for this type of task.\nI hope this article helped you understand the usage of these data structures and when to use them.\n* * *\n**FREE PYTHON EBOOK:**\nStarted learning Python Data Science but struggling with it? [_**Subscribe to my newsletter and get my free ebook: this will give you the right learning path to follow to learn Python for Data Science with hands-on experience.**_](https://federico-trotta.ck.page/a3970f33f4)\nEnjoyed the story? Become a Medium member for 5$/month [through my referral link](https://medium.com/@federicotrotta/membership): I'll earn a small commission to no additional fee to you:\n> [**Join Medium with my referral link - Federico Trotta**](https://medium.com/@federicotrotta/membership)\n## Register Now to Continue Reading\n### Unlock Towards Data Science with a Free Account\nAll articles on Towards Data Science are available to registered users. Create a free account today to access this article and thousands more.\nRegister for freeSign in to your account\n* * *\n![](https://assets.insightmediagroup.io/media/1787657183787_vf5bj8.png)\nWritten By\n## [Federico Trotta](https://towardsdatascience.com/author/federicotrotta/)\n[See all from Federico Trotta](https://towardsdatascience.com/author/federicotrotta/)\n[Data Science](https://towardsdatascience.com/tag/data-science/)[Federico Trotta](https://towardsdatascience.com/tag/federico-trotta/)[Machine Learning](https://towardsdatascience.com/tag/machine-learning/)[Programming](https://towardsdatascience.com/tag/programming/)[Python](https://towardsdatascience.com/tag/python/)\nShare This Article\n  * [](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Ftowardsdatascience.com%2Flists-tuples-dictionaries-and-data-frames-in-python-the-complete-guide-7ab54d4819ee%2F&title=Lists%2C%20Tuples%2C%20Dictionaries%2C%20And%20Data%20Frames%20in%20Python%3A%20The%20Complete%20Guide)\n  * [](https://www.linkedin.com/shareArticle?mini=true&url=https%3A%2F%2Ftowardsdatascience.com%2Flists-tuples-dictionaries-and-data-frames-in-python-the-complete-guide-7ab54d4819ee%2F&title=Lists%2C%20Tuples%2C%20Dictionaries%2C%20And%20Data%20Frames%20in%20Python%3A%20The%20Complete%20Guide)\n  * [](https://x.com/share?url=https%3A%2F%2Ftowardsdatascience.com%2Flists-tuples-dictionaries-and-data-frames-in-python-the-complete-guide-7ab54d4819ee%2F&text=Lists%2C%20Tuples%2C%20Dictionaries%2C%20And%20Data%20Frames%20in%20Python%3A%20The%20Complete%20Guide)\n\n\nTowards Data Science is a community publication. Submit your insights to reach our global audience and earn through the TDS Author Payment Program.\n[Write for TDS](https://towardsdatascience.com/submissions/)\n## Related Articles\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2021/04/11Rd1AOfn-yh7pGzNHpmPjw-scaled.jpeg)](https://towardsdatascience.com/detecting-disaster-from-tweets-classical-ml-and-lstm-approach-4566871af5f7/)\n## [Detecting Disaster from Tweets (classical ML and LSTM approach)](https://towardsdatascience.com/detecting-disaster-from-tweets-classical-ml-and-lstm-approach-4566871af5f7/)\n[Machine Learning](https://towardsdatascience.com/category/artificial-intelligence/machine-learning/)\nA Classification task using NLP and comparing two approaches.\n[Mazi Boustani](https://towardsdatascience.com/author/maziboustani/)\nApril 6, 202110 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2022/01/0acvmstqLzk00ViTW-scaled.jpg)](https://towardsdatascience.com/whats-in-a-tuple-5d4b2668b9a1/)\n## [What's in a Tuple?](https://towardsdatascience.com/whats-in-a-tuple-5d4b2668b9a1/)\n[Programming](https://towardsdatascience.com/category/programming/)\nAn overview of Python's alternative to lists and why you should use them\n[Murtaza Ali](https://towardsdatascience.com/author/murtaza5152-ali/)\nJanuary 19, 20224 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2021/04/0F0A4OspOmObSFFBv-scaled.jpg)](https://towardsdatascience.com/introduction-to-apache-kafka-with-wikipedias-eventstreams-service-d06d4628e8d9/)\n## [Introduction to Apache Kafka with Wikipedia's EventStreams service](https://towardsdatascience.com/introduction-to-apache-kafka-with-wikipedias-eventstreams-service-d06d4628e8d9/)\n[](https://towardsdatascience.com/lists-tuples-dictionaries-and-data-frames-in-python-the-complete-guide-7ab54d4819ee/)\nConcepts and hands-on examples\n[Zisis Flokas](https://towardsdatascience.com/author/zisisflokas/)\nApril 10, 20217 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2023/02/0ZO7FcGv308eH6QOx-scaled.jpg)](https://towardsdatascience.com/how-industry-data-scientists-make-their-work-count-f552739afd15/)\n## [How Industry Data Scientists Make Their Work Count](https://towardsdatascience.com/how-industry-data-scientists-make-their-work-count-f552739afd15/)\n[Data Science](https://towardsdatascience.com/category/data-science/)\nOur weekly selection of must-read Editors' Picks and original features\n[TDS Editors](https://towardsdatascience.com/author/towardsdatascience/)\nFebruary 2, 20233 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2022/04/0d-qLPzbyiI0tSIFU-scaled.jpg)](https://towardsdatascience.com/how-to-get-a-technical-internship-a-detailed-guide-ecd4e1b68154/)\n## [How to Get a Technical Internship - A Detailed Guide](https://towardsdatascience.com/how-to-get-a-technical-internship-a-detailed-guide-ecd4e1b68154/)\n[Programming](https://towardsdatascience.com/category/programming/)\nFamiliarize yourself with the three-step process for navigating the tech landscape.\n[Murtaza Ali](https://towardsdatascience.com/author/murtaza5152-ali/)\nApril 8, 202212 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2020/09/1wNae5HXt7xFiCO1oZyJQXw-scaled.jpeg)](https://towardsdatascience.com/7-key-points-on-7-machine-learning-algorithms-945ebda7a79/)\n## [7 Key Points on 7 Machine Learning Algorithms](https://towardsdatascience.com/7-key-points-on-7-machine-learning-algorithms-945ebda7a79/)\n[Artificial Intelligence](https://towardsdatascience.com/category/artificial-intelligence/)\nWhat is going on under the hood?\n[Soner Yıldırım](https://towardsdatascience.com/author/sonery/)\nSeptember 9, 20206 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2025/04/python-racing-turtle.png)](https://towardsdatascience.com/how-to-optimize-your-python-program-for-slowness/)\n## [How to Optimize your Python Program for Slowness](https://towardsdatascience.com/how-to-optimize-your-python-program-for-slowness/)\n[Programming](https://towardsdatascience.com/category/programming/)\nWrite a short program that finishes after the universe dies\n[Carl Kadie](https://towardsdatascience.com/author/carlmkadie/)\nApril 7, 202518 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2022/08/1iD0X6Ni5rFOpAToP9tAy1g-scaled.jpeg)](https://towardsdatascience.com/the-seven-stages-of-mlops-maturity-ccb029530f2/)\n## [The Seven Stages of MLOps Maturity](https://towardsdatascience.com/the-seven-stages-of-mlops-maturity-ccb029530f2/)\n[Artificial Intelligence](https://towardsdatascience.com/category/artificial-intelligence/)\nA practical guide to building critical MLOps capabilities that maximize data science ROI\n[Josh Poduska](https://towardsdatascience.com/author/josh_domino/)\nAugust 25, 20228 min read\n  * [![](https://assets.insightmediagroup.io/media/wp-content/uploads/2020/11/06gqaT61-sCG40zvJ.jpg)](https://towardsdatascience.com/7-great-functions-for-your-exploratory-analysis-in-r-a569de3db3a/)\n## [7 great functions for your Exploratory Analysis in R](https://towardsdatascience.com/7-great-functions-for-your-exploratory-analysis-in-r-a569de3db3a/)\n[Data Science](https://towardsdatascience.com/category/data-science/)\n7 functions to improve your EDA process in R\n[Rafael Belokurows](https://towardsdatascience.com/author/rafabelokurows/)\nNovember 4, 20206 min read\n\n\n  * [YouTube](https://www.youtube.com/c/TowardsDataScience)\n  * [X](https://x.com/TDataScience)\n  * [LinkedIn](https://www.linkedin.com/company/towards-data-science/)\n  * [Threads](https://www.threads.net/@towardsdatascience)\n  * [Bluesky](https://bsky.app/profile/towardsdatascience.com)\n\n\n[](https://towardsdatascience.com/)\nYour home for data science and AI. The world's leading publication for data science, data analytics, data engineering, machine learning, and artificial intelligence professionals.\nSubscribe to Our Newsletter[Write For TDS](https://towardsdatascience.com/submissions/)•[About](https://towardsdatascience.com/about-towards-data-science-d691af11cc2f/)•[Advertise](https://contact.towardsdatascience.com/advertise-with-towards-data-science)•[Privacy Policy](https://towardsdatascience.com/privacy-policy/)•[Terms of Use](https://towardsdatascience.com/website-terms-of-use/)\n© Insight Media Group, LLC 2026•[The New Stack](https://thenewstack.io)•[roadmap.sh](https://roadmap.sh)•[Creator Network](https://insightmediagroup.io/creator-network)\n####  Recommended Articles \nClose\n  * [ ![](https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/607631/image?etag=1781543525510&width=500&height=500) Critical Mistakes Companies Make When Integrating AI/ML into Their Processes ](https://towardsdatascience.com/critical-mistakes-companies-make-when-integrating-ai-ml-into-their-processes/ \"Critical Mistakes Companies Make When Integrating AI/ML into Their Processes\")\n  * [ ![](https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/607686/image?etag=1782161464448&width=500&height=500) How Relevance Models Foreshadowed Transformers for NLP ](https://towardsdatascience.com/how-relevance-models-foreshadowed-transformers-for-nlp/ \"How Relevance Models Foreshadowed Transformers for NLP\")\n  * [ ![](https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/607639/image?etag=1781250125848&width=500&height=500) Javascript Fatigue: HTMX Is All You Need to Build ChatGPT — Part 1 ](https://towardsdatascience.com/javascript-fatigue-you-dont-need-js-to-build-chatgpt/ \"Javascript Fatigue: HTMX Is All You Need to Build ChatGPT — Part 1\")\n  * [ ![](https://h030.towardsdatascience.com/rest/v2/contentStores/d7d3a4ab-7caf-4383-bbd2-fbf7fb4f1787/items/607930/image?etag=1782124566054&width=500&height=500) The Subset Sum Problem Solved in Linear Time for Dense Enough Inputs ](https://towardsdatascience.com/subset-sum-problem-solved-in-linear-time-for-dense-enough-inputs/ \"The Subset Sum Problem Solved in Linear Time for Dense Enough Inputs\")\n\n\n",
  "metadata": {
    "title": "Lists, Tuples, Dictionaries, And Data Frames in Python: The Complete Guide | Towards Data Science",
    "description": "All you need to know to master the most used data structures in Python",
    "keywords": null,
    "author": "Federico Trotta",
    "og:locale": "en_US",
    "og:type": "article",
    "og:title": "Lists, Tuples, Dictionaries, And Data Frames in Python: The Complete Guide",
    "og:description": "All you need to know to master the most used data structures in Python",
    "og:url": "https://towardsdatascience.com/lists-tuples-dictionaries-and-data-frames-in-python-the-complete-guide-7ab54d4819ee/",
    "og:site_name": "Towards Data Science",
    "og:image": "https://assets.insightmediagroup.io/media/wp-content/uploads/2023/05/132atRC8027o3BkGPCgP1Yg.jpeg",
    "og:image:width": "1920",
    "og:image:height": "1281",
    "og:image:type": "image/jpeg",
    "twitter:card": "summary_large_image",
    "twitter:site": "@TDataScience",
    "twitter:creator": "@TDataScience",
    "twitter:label1": "Written by",
    "twitter:data1": "Federico Trotta",
    "twitter:label2": "Est. reading time",
    "twitter:data2": "17 min read",
    "article:published_time": "2023-05-24T03:09:28.000Z",
    "article:modified_time": "2023-05-24T03:09:28.000Z",
    "article:author": "https://towardsdatascience.com/author/federicotrotta/"
  },
  "paywall": {
    "listed_paid": true,
    "detected": false,
    "marker": "",
    "public_only": true,
    "policy": "付费/会员内容只保留页面公开可见部分，不绕过付费墙"
  },
  "crawl": {
    "success": true,
    "status_code": 200,
    "error": ""
  },
  "code_blocks": [
    {
      "language": "txt",
      "file": "attachments/d8f015b8f423/code/block_000.txt",
      "chars": 276
    },
    {
      "language": "txt",
      "file": "attachments/d8f015b8f423/code/block_001.txt",
      "chars": 59
    },
    {
      "language": "txt",
      "file": "attachments/d8f015b8f423/code/block_002.txt",
      "chars": 63
    },
    {
      "language": "txt",
      "file": "attachments/d8f015b8f423/code/block_003.txt",
      "chars": 102
    },
    {
      "language": "txt",
      "file": "attachments/d8f015b8f423/code/block_004.txt",
      "chars": 107
    },
    {
      "language": "txt",
      "file": "attachments/d8f015b8f423/code/block_005.txt",
      "chars": 104
    },
    {
      "language": "txt",
      "file": "attachments/d8f015b8f423/code/block_006.txt",
      "chars": 217
    },
    {
      "language": "txt",
      "file": "attachments/d8f015b8f423/code/block_007.txt",
      "chars": 226
    },
    {
      "language": "txt",
      "file": "attachments/d8f015b8f423/code/block_008.txt",
      "chars": 228
    },
    {
      "language": "txt",
      "file": "attachments/d8f015b8f423/code/block_009.txt",
      "chars": 198
    },
    {
      "language": "txt",
      "file": "attachments/d8f015b8f423/code/block_010.txt",
      "chars": 170
    },
    {
      "language": "txt",
      "file": "attachments/d8f015b8f423/code/block_011.txt",
      "chars": 139
    },
    {
      "language": "txt",
      "file": "attachments/d8f015b8f423/code/block_012.txt",
      "chars": 133
    },
    {
      "language": "txt",
      "file": "attachments/d8f015b8f423/code/block_013.txt",
      "chars": 169
    },
    {
      "language": "txt",
      "file": "attachments/d8f015b8f423/code/block_014.txt",
      "chars": 330
    },
    {
      "language": "txt",
      "file": "attachments/d8f015b8f423/code/block_015.txt",
      "chars": 235
    },
    {
      "language": "txt",
      "file": "attachments/d8f015b8f423/code/block_016.txt",
      "chars": 200
    },
    {
      "language": "txt",
      "file": "attachments/d8f015b8f423/code/block_017.txt",
      "chars": 191
    },
    {
      "language": "txt",
      "file": "attachments/d8f015b8f423/code/block_018.txt",
      "chars": 383
    },
    {
      "language": "txt",
      "file": "attachments/d8f015b8f423/code/block_019.txt",
      "chars": 192
    },
    {
      "language": "txt",
      "file": "attachments/d8f015b8f423/code/block_020.txt",
      "chars": 404
    },
    {
      "language": "txt",
      "file": "attachments/d8f015b8f423/code/block_021.txt",
      "chars": 101
    },
    {
      "language": "txt",
      "file": "attachments/d8f015b8f423/code/block_022.txt",
      "chars": 178
    },
    {
      "language": "txt",
      "file": "attachments/d8f015b8f423/code/block_023.txt",
      "chars": 113
    },
    {
      "language": "txt",
      "file": "attachments/d8f015b8f423/code/block_024.txt",
      "chars": 111
    },
    {
      "language": "txt",
      "file": "attachments/d8f015b8f423/code/block_025.txt",
      "chars": 77
    },
    {
      "language": "txt",
      "file": "attachments/d8f015b8f423/code/block_026.txt",
      "chars": 144
    },
    {
      "language": "txt",
      "file": "attachments/d8f015b8f423/code/block_027.txt",
      "chars": 146
    },
    {
      "language": "txt",
      "file": "attachments/d8f015b8f423/code/block_028.txt",
      "chars": 256
    },
    {
      "language": "txt",
      "file": "attachments/d8f015b8f423/code/block_029.txt",
      "chars": 263
    },
    {
      "language": "txt",
      "file": "attachments/d8f015b8f423/code/block_030.txt",
      "chars": 191
    },
    {
      "language": "txt",
      "file": "attachments/d8f015b8f423/code/block_031.txt",
      "chars": 159
    },
    {
      "language": "txt",
      "file": "attachments/d8f015b8f423/code/block_032.txt",
      "chars": 139
    },
    {
      "language": "txt",
      "file": "attachments/d8f015b8f423/code/block_033.txt",
      "chars": 348
    },
    {
      "language": "txt",
      "file": "attachments/d8f015b8f423/code/block_034.txt",
      "chars": 146
    },
    {
      "language": "txt",
      "file": "attachments/d8f015b8f423/code/block_035.txt",
      "chars": 355
    },
    {
      "language": "txt",
      "file": "attachments/d8f015b8f423/code/block_036.txt",
      "chars": 50
    },
    {
      "language": "txt",
      "file": "attachments/d8f015b8f423/code/block_037.txt",
      "chars": 342
    },
    {
      "language": "txt",
      "file": "attachments/d8f015b8f423/code/block_038.txt",
      "chars": 143
    },
    {
      "language": "txt",
      "file": "attachments/d8f015b8f423/code/block_039.txt",
      "chars": 333
    },
    {
      "language": "txt",
      "file": "attachments/d8f015b8f423/code/block_040.txt",
      "chars": 58
    },
    {
      "language": "txt",
      "file": "attachments/d8f015b8f423/code/block_041.txt",
      "chars": 128
    },
    {
      "language": "txt",
      "file": "attachments/d8f015b8f423/code/block_042.txt",
      "chars": 70
    },
    {
      "language": "txt",
      "file": "attachments/d8f015b8f423/code/block_043.txt",
      "chars": 49
    }
  ],
  "images": [
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2023/05/132atRC8027o3BkGPCgP1Yg.jpeg",
      "alt": "Image by Pexels on Pixabay",
      "local_path": "attachments/d8f015b8f423/images/000.jpeg",
      "bytes": 438488,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2023/05/1ktO7pYF7T7GyzKZnmHa80w.jpeg",
      "alt": "A data frame is the representation of tabular data. Image from the Panda&#039;s website here: https://pandas.pydata.org/docs/getting_started/index.html",
      "local_path": "attachments/d8f015b8f423/images/001.jpeg",
      "bytes": 14030,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2023/05/1jlh4l3iTHFc7Klh4Tc2_JQ.png",
      "alt": "A data frame. Image by Federico Trotta.",
      "local_path": "attachments/d8f015b8f423/images/002.png",
      "bytes": 4124,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2023/05/1ypgHf93Txw6oOwUPwuLGew.png",
      "alt": "What df.head() shows. Image by Federico Trotta.",
      "local_path": "attachments/d8f015b8f423/images/003.png",
      "bytes": 3992,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2023/05/1o5rKF43Mba8o_GPgPL9pHw.png",
      "alt": "What print(df) shows. Image by Federico Trotta.",
      "local_path": "attachments/d8f015b8f423/images/004.png",
      "bytes": 3437,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2023/05/1CaEn3BWt4M5-4Ci4C0zOVQ.png",
      "alt": "The data frame df with the marital status. Image by Federico Trotta.",
      "local_path": "attachments/d8f015b8f423/images/005.png",
      "bytes": 4494,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2023/05/1JCgn0p7knJWMqtqcUovUxg.png",
      "alt": "The data frame without the column related to employment data. Image by Federico Trotta.",
      "local_path": "attachments/d8f015b8f423/images/006.png",
      "bytes": 3747,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2023/05/1jFWAyKYpBesDMjiLEUxqyQ.png",
      "alt": "The data frame without the second row. Image by Federico Trotta.",
      "local_path": "attachments/d8f015b8f423/images/007.png",
      "bytes": 2989,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2021/04/11Rd1AOfn-yh7pGzNHpmPjw-scaled.jpeg",
      "alt": "",
      "local_path": "attachments/d8f015b8f423/images/008.jpeg",
      "bytes": 990126,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2022/01/0acvmstqLzk00ViTW-scaled.jpg",
      "alt": "",
      "local_path": "attachments/d8f015b8f423/images/009.jpg",
      "bytes": 560409,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2021/04/0F0A4OspOmObSFFBv-scaled.jpg",
      "alt": "",
      "local_path": "attachments/d8f015b8f423/images/010.jpg",
      "bytes": 956463,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2023/02/0ZO7FcGv308eH6QOx-scaled.jpg",
      "alt": "",
      "local_path": "attachments/d8f015b8f423/images/011.jpg",
      "bytes": 292607,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2022/04/0d-qLPzbyiI0tSIFU-scaled.jpg",
      "alt": "",
      "local_path": "attachments/d8f015b8f423/images/012.jpg",
      "bytes": 247560,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2020/09/1wNae5HXt7xFiCO1oZyJQXw-scaled.jpeg",
      "alt": "",
      "local_path": "attachments/d8f015b8f423/images/013.jpeg",
      "bytes": 673123,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2025/04/python-racing-turtle.png",
      "alt": "",
      "local_path": "attachments/d8f015b8f423/images/014.png",
      "bytes": 722482,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2022/08/1iD0X6Ni5rFOpAToP9tAy1g-scaled.jpeg",
      "alt": "",
      "local_path": "attachments/d8f015b8f423/images/015.jpeg",
      "bytes": 191235,
      "downloaded": true
    },
    {
      "src": "https://assets.insightmediagroup.io/media/wp-content/uploads/2020/11/06gqaT61-sCG40zvJ.jpg",
      "alt": "",
      "local_path": "attachments/d8f015b8f423/images/016.jpg",
      "bytes": 238721,
      "downloaded": true
    }
  ],
  "audio": [],
  "videos": [
    {
      "src": "https://www.youtube.com/c/TowardsDataScience",
      "quality": "unavailable",
      "local_path": "",
      "note": "无1080p且无720p，未交付更低清晰度"
    }
  ],
  "links": [
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/latest/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/editors-pick/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/the-variable/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/shipai/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/submissions/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/category/data-science/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/author/federicotrotta/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/loops-and-statements-in-python-a-deep-understanding-with-examples-2099fc6e37d7"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/python-loops-a-complete-guide-on-how-to-iterate-in-python-b29e0d12211d"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/data-science/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/federico-trotta/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/machine-learning/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/programming/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/tag/python/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/detecting-disaster-from-tweets-classical-ml-and-lstm-approach-4566871af5f7/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/category/artificial-intelligence/machine-learning/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/author/maziboustani/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/whats-in-a-tuple-5d4b2668b9a1/"
    },
    {
      "type": "internal",
      "href": "https://towardsdatascience.com/category/programming/"
    },
    {
      "type": "external",
      "href": "https://write.insightmediagroup.io"
    },
    {
      "type": "external",
      "href": "https://www.linkedin.com/company/towards-data-science/"
    },
    {
      "type": "external",
      "href": "https://x.com/TDataScience"
    },
    {
      "type": "external",
      "href": "https://pixabay.com/it/users/pexels-2286921/"
    },
    {
      "type": "external",
      "href": "https://pixabay.com/it//"
    },
    {
      "type": "external",
      "href": "https://roadmap.sh/ai-data-scientist"
    },
    {
      "type": "external",
      "href": "https://roadmap.sh/computer-science"
    },
    {
      "type": "external",
      "href": "https://roadmap.sh/machine-learning"
    },
    {
      "type": "external",
      "href": "https://pandas.pydata.org/docs/getting_started/index.html"
    },
    {
      "type": "external",
      "href": "https://federico-trotta.ck.page/a3970f33f4"
    },
    {
      "type": "external",
      "href": "https://medium.com/@federicotrotta/membership"
    },
    {
      "type": "external",
      "href": "https://www.facebook.com/sharer/sharer.php?title=Lists%2C+Tuples%2C+Dictionaries%2C+And+Data+Frames+in+Python%3A+The+Complete+Guide&u=https%3A%2F%2Ftowardsdatascience.com%2Flists-tuples-dictionaries-and-data-frames-in-python-the-complete-guide-7ab54d4819ee%2F"
    },
    {
      "type": "external",
      "href": "https://www.linkedin.com/shareArticle?mini=true&title=Lists%2C+Tuples%2C+Dictionaries%2C+And+Data+Frames+in+Python%3A+The+Complete+Guide&url=https%3A%2F%2Ftowardsdatascience.com%2Flists-tuples-dictionaries-and-data-frames-in-python-the-complete-guide-7ab54d4819ee%2F"
    },
    {
      "type": "external",
      "href": "https://x.com/share?text=Lists%2C+Tuples%2C+Dictionaries%2C+And+Data+Frames+in+Python%3A+The+Complete+Guide&url=https%3A%2F%2Ftowardsdatascience.com%2Flists-tuples-dictionaries-and-data-frames-in-python-the-complete-guide-7ab54d4819ee%2F"
    },
    {
      "type": "external",
      "href": "https://www.youtube.com/c/TowardsDataScience"
    },
    {
      "type": "external",
      "href": "https://www.threads.net/@towardsdatascience"
    },
    {
      "type": "external",
      "href": "https://bsky.app/profile/towardsdatascience.com"
    },
    {
      "type": "external",
      "href": "https://thenewstack.io"
    },
    {
      "type": "external",
      "href": "https://roadmap.sh"
    },
    {
      "type": "external",
      "href": "https://insightmediagroup.io/creator-network"
    }
  ],
  "repair_version": 2,
  "repaired_at": "2026-10-14T11:11:49Z",
  "source_url": "https://towardsdatascience.com/lists-tuples-dictionaries-and-data-frames-in-python-the-complete-guide-7ab54d4819ee/",
  "delivery_status": "excluded_paid",
  "discovery_status": "excluded_paid",
  "missing_reason": "按原约定排除付费/会员全文"
}