Telegram Group & Telegram Channel
Работаем с данными

pandas - это мощный инструмент для анализа данных в Python. С помощью данного фреймворка, работа с «реляционными» или «помеченными» данными простой и интуитивно понятной. Сегодня мы применим его для модификации csv файла.

Чтобы загрузить датафрейм из файла (пример), используем метод pd.read_csv().

Применим фильтр по полю sepal.length > 5. В SQL данная операция выглядела бы таким образом:
SELECT * FROM df WHERE sepal.length > 5.
В pandas же для получения необходимых строк фрейма можем использовать метод loc, передав в нее необходимый фильтр:
df = df.loc[df['sepal.length'] > 5]

Для удаления одной или нескольких колонок можно использовать метод df.drop():
df = df.drop(columns=['petal.width', 'petal.length'])

При сохранении в файл мы можем дополнительно указать pandas не добавлять генерирующийся индекс строкам, если он нам не нужен:
df.to_csv('new_iris.csv', index = False)

#pandas



tg-me.com/python_academy/744
Create:
Last Update:

Работаем с данными

pandas - это мощный инструмент для анализа данных в Python. С помощью данного фреймворка, работа с «реляционными» или «помеченными» данными простой и интуитивно понятной. Сегодня мы применим его для модификации csv файла.

Чтобы загрузить датафрейм из файла (пример), используем метод pd.read_csv().

Применим фильтр по полю sepal.length > 5. В SQL данная операция выглядела бы таким образом:
SELECT * FROM df WHERE sepal.length > 5.
В pandas же для получения необходимых строк фрейма можем использовать метод loc, передав в нее необходимый фильтр:
df = df.loc[df['sepal.length'] > 5]

Для удаления одной или нескольких колонок можно использовать метод df.drop():
df = df.drop(columns=['petal.width', 'petal.length'])

При сохранении в файл мы можем дополнительно указать pandas не добавлять генерирующийся индекс строкам, если он нам не нужен:
df.to_csv('new_iris.csv', index = False)

#pandas

BY Python Academy




Share with your friend now:
tg-me.com/python_academy/744

View MORE
Open in Telegram


Python Academy Telegram | DID YOU KNOW?

Date: |

Start with a fresh view of investing strategy. The combination of risks and fads this quarter looks to be topping. That means the future is ready to move in.Likely, there will not be a wholesale shift. Company actions will aim to benefit from economic growth, inflationary pressures and a return of market-determined interest rates. In turn, all of that should drive the stock market and investment returns higher.

How to Use Bitcoin?

n the U.S. people generally use Bitcoin as an alternative investment, helping diversify a portfolio apart from stocks and bonds. You can also use Bitcoin to make purchases, but the number of vendors that accept the cryptocurrency is still limited. Big companies that accept Bitcoin include Overstock, AT&T and Twitch. You may also find that some small local retailers or certain websites take Bitcoin, but you’ll have to do some digging. That said, PayPal has announced that it will enable cryptocurrency as a funding source for purchases this year, financing purchases by automatically converting crypto holdings to fiat currency for users. “They have 346 million users and they’re connected to 26 million merchants,” says Spencer Montgomery, founder of Uinta Crypto Consulting. “It’s huge.”

Python Academy from id


Telegram Python Academy
FROM USA