Python Tutorial: Data types and data merging
Want to learn more? Take the full course at https://learn.datacamp.com/courses/an... at your own pace. More than a video, you'll learn hands-on coding & quickly apply skills to your daily work.
---
In this lesson, we will talk about various techniques to manipulate data using Pandas.
Each column in a pandas DataFrame has a specific data type. Some of the common data types are strings (which are represented as objects), numbers, boolean values (which are True/False) and dates.
You can use the dtype attribute if you are interested in knowing the data type of a single column.
To change the data type of a column, you can use the astype() method. For example, you saw on the earlier slide that the converted column is stored as an object. It contains True and False values, so it's more appropriate to store it as a boolean. You can use the astype() method along with the argument 'bool' as shown here to change its data type.
If you check the data type of the 'converted' column again, you will see that it's now 'bool'.
The marketing_channel column captures the channel a user saw a marketing asset on. Say you want to have a column that identifies if a particular marketing asset was a house ad or not.
You can use numpy's where() function to create a new boolean column to establish this. The first argument is an expression that checks whether the value in the marketing_channel column is 'House Ads', the second argument is the value you want to assign if the expression is true, and the third argument is the value you want to assign if the expression is false.
Due to the way pandas stores data, in a large dataset, it can be computationally inefficient to store columns of strings. In such cases, it can speed things up to instead store these values as numbers.
To create a column with channel codes, build a dictionary that maps the channels to numerical codes. Then, use the map() method on the channel column along with this dictionary, as shown here.
Often, you will have date columns that are improperly read as objects by pandas. However, as you will see in the following lessons, having date columns properly imported as the datetime datatype has several advantages.
You have two options to ensure that certain columns are treated as dates. First, when importing the dataset using the read_csv() function, you can pass a list of column names to the parse_dates argument to ensure that these columns are correctly interpreted as date columns.
Another option is to use the pandas' datetime() function to convert a specific column.
Once the dates in the column are properly imported, you can use various date attributes to extract relevant information.
For example, to obtain the day of the week, you can use the dayofweek attribute along with the dt accessor on the date column. This will result in a numerical value where 0 maps to Monday, 1 to Tuesday, and so on.
It's time for you to practice these concepts.
#PythonTutorial #pandas #marketing #DataCamp #Python
Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «Python Tutorial: Data types and data merging», вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.
Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.
Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!
Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.