pandas

Python Get Printed Output into Dataframe

好久不见. 提交于 2021-02-11 14:31:31
问题 I am having trouble getting the printed output of a python script into a data frame. When I execute the script the information I want in the data frame prints, but the script creates an empty table in SQL. I believe there's something wrong with the structure of my script at the point where I try to get the results into a data frame. --- import requests from bs4 import BeautifulSoup from urllib.parse import urlparse, parse_qs headers = ({'User-Agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit

subset dataframe to show on GUI Tkinter

社会主义新天地 提交于 2021-02-11 14:31:14
问题 I have dropdown option in tkinter which select the option of dropdown by groupby the col1 by dataframe pandas , Now I am able to see the subset of dataframe by clicking ok button in my terminal , I want to see the subset dataframe after selecting into dropdown in my GUI , Please let me know how to see the subset dataframe a/c to dropdown option into my GUI . import tkinter as tk import pandas as pd # --- functions --- def on_click(): val = selected.get() if val == 'all': print(df) else: df2 =

Python Get Printed Output into Dataframe

不想你离开。 提交于 2021-02-11 14:30:38
问题 I am having trouble getting the printed output of a python script into a data frame. When I execute the script the information I want in the data frame prints, but the script creates an empty table in SQL. I believe there's something wrong with the structure of my script at the point where I try to get the results into a data frame. --- import requests from bs4 import BeautifulSoup from urllib.parse import urlparse, parse_qs headers = ({'User-Agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit

What's the most efficient way to convert a time-series data into a cross-sectional one?

本小妞迷上赌 提交于 2021-02-11 14:30:25
问题 Here's the thing, I have the dataset below where date is the index: date value 2020-01-01 100 2020-02-01 140 2020-03-01 156 2020-04-01 161 2020-05-01 170 . . . And I want to transform it in this other dataset: value_t0 value_t1 value_t2 value_t3 value_t4 ... 100 NaN NaN NaN NaN ... 140 100 NaN NaN NaN ... 156 140 100 NaN NaN ... 161 156 140 100 NaN ... 170 161 156 140 100 ... First I thought about using pandas.pivot_table to do something, but that would just provide a different layout grouped

Geopandas userdefined color scheme drops colors

こ雲淡風輕ζ 提交于 2021-02-11 14:24:30
问题 I expected to get a legend of the three colors green, yellow and red, even if the bottom range is empty (no numbers below 10). Instead GeoPandas drops the yellow color and uses green twice. Is this a bug or do I miss a parameter? import pandas as pd import geopandas from matplotlib.colors import ListedColormap colors = ['green', 'yellow', 'red'] bins = [10, 30] numbers = [15, 25, 35, 35, 55] ny = geopandas.read_file(geopandas.datasets.get_path('nybb')) numbers = pd.Series(numbers, name=

pandas groupby: an overall/total row?

*爱你&永不变心* 提交于 2021-02-11 14:18:44
问题 I have the following: maths = {'floatval': 'mean'} out = df.groupby(['pid', 'year', 'month']).agg(maths) Which gives me a grouped mean of floatval per year and month, which is great, but I want an all/overall row, which has the mean val of floatval across a row just grouped by pid . Should I make a second data frame and combine, or is there a more efficient way? 来源: https://stackoverflow.com/questions/51712739/pandas-groupby-an-overall-total-row

How could I solve this error to scrape Twitter with Python?

a 夏天 提交于 2021-02-11 14:18:33
问题 I'm trying to do a personal project for my portfolio, I would like to scrape the tweets about the president Macron but I get this error with twitterscrapper . from twitterscraper import query_tweets import datetime as dt import pandas as pd begin_date=dt.date(2020,11,18) end_date=dt.date(2020,11,19) limit=1000 lang='English' tweets=query_tweets("#macron",begindate=begin_date,enddate=end_date,limit=limit,lang=lang) Error: TypeError: query_tweets() got an unexpected keyword argument 'begindate'

Exporting DataFrame to Excel using pandas without subscribe

耗尽温柔 提交于 2021-02-11 14:18:03
问题 How can I export DataFrame to excel without subscribe? For exemple: I'm doing webscraping and there is a table with pagination, so I take the page 1 save it in DataFrame, export to excel e do it again in page 2. But every record is erased when a save it remaining the last one. Sorry for my english, here is my code: import time import pandas as pd from bs4 import BeautifulSoup from selenium import webdriver i=1 url = "https://stats.nba.com/players/traditional/?PerMode=Totals&Season=2019-20

Calculate nearest distance to certain points in python

微笑、不失礼 提交于 2021-02-11 14:16:19
问题 I have a dataset as shown below, each sample has x and y values and the corresponding result Sr. X Y Resut 1 2 12 Positive 2 4 3 positive .... Visualization Grid size is 12 * 8 How I can calculate the nearest distance for each sample from red points (positive ones)? Red = Positive, Blue = Negative Sr. X Y Result Nearest-distance-red 1 2 23 Positive ? 2 4 3 Negative ? .... dataset 回答1: Its a lot easier when there is sample data, make sure to include that next time. I generate random data

How do I test if Point is in Polygon/Multipolygon with geopandas in Python?

こ雲淡風輕ζ 提交于 2021-02-11 14:15:58
问题 I have the Polygon data from the States from the USA from the website arcgis and I also have an excel file with coordinates of citys. I have converted the coordinates to geometry data (Points). Now I want to test if the Points are in the USA. Both are dtype: geometry. I thought with this I can easily compare, but when I use my code I get for every Point the answer false. Even if there are Points that are in the USA. The code is: import geopandas as gp import pandas as pd import xlsxwriter