python-3.x

Pandas read_excel() parses date columns with blank values to NaT

谁都会走 提交于 2021-02-08 10:50:47
问题 I am trying to read an excel file that has date columns with the below code src1_df = pd.read_excel("src_file1.xlsx", keep_default_na = False) Even though I have specified, keep_default_na = False, I see that the data frame has 'NaT' value(s) for corresponding blank cells in Excel date columns. Please suggest, how to get a blank string instead of 'NaT' while parsing Excel files. I am using Python 3.x and Pandas 0.23.4 回答1: src1_df = pd.read_excel("src_file1.xlsx", na_filter=False) Then you

Pandas parsing csv error - expected 1 fields found 9

拈花ヽ惹草 提交于 2021-02-08 10:50:23
问题 I'm trying to parse from a .csv file: planets = pd.read_csv("planets.csv", sep=',') But I always end up with this error: ParserError: Error tokenizing data. C error: Expected 1 fields in line 13, saw 9 This is how the first few lines of my csv file look like: # This file was produced by the test # Tue Apr 3 06:03:27 2018 # # COLUMN pl_hostname: Host Name # COLUMN pl_discmethod: Discovery Method # COLUMN pl_pnum: Number of Planets in System # COLUMN pl_orbper: Orbital Period [days] # COLUMN pl

How to set Collation in MySQL database with Django 2.* mysqlclient?

僤鯓⒐⒋嵵緔 提交于 2021-02-08 10:49:40
问题 I need to set default Collation for MySQL tables with Django 2.*, im using mysqlclient, my settings are: DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': '', 'USER': '', 'PASSWORD': '', 'HOST': 'localhost', 'PORT': '3306', 'OPTIONS': { 'charset': 'utf8mb4', }, } } 'charset': 'utf8mb4', This parameter seems don't work properly and tables in DB utf8. Although i want to manually set and tables Collation to utf8mb4_general_ci Will be appreciate for any clues. 回答1: 'default

How to set Collation in MySQL database with Django 2.* mysqlclient?

喜欢而已 提交于 2021-02-08 10:48:35
问题 I need to set default Collation for MySQL tables with Django 2.*, im using mysqlclient, my settings are: DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': '', 'USER': '', 'PASSWORD': '', 'HOST': 'localhost', 'PORT': '3306', 'OPTIONS': { 'charset': 'utf8mb4', }, } } 'charset': 'utf8mb4', This parameter seems don't work properly and tables in DB utf8. Although i want to manually set and tables Collation to utf8mb4_general_ci Will be appreciate for any clues. 回答1: 'default

pandas sum the differences between two columns in each group

自作多情 提交于 2021-02-08 10:48:33
问题 I have a df looks like, A B C D 2017-10-01 2017-10-11 M 2017-10 2017-10-02 2017-10-03 M 2017-10 2017-11-01 2017-11-04 B 2017-11 2017-11-08 2017-11-09 B 2017-11 2018-01-01 2018-01-03 A 2018-01 the dtype of A and B are datetime64 , C and D are of strings ; I like to groupby C and D and get the differences between B and A , df.groupby(['C', 'D']).apply(lambda row: row['B'] - row['A']) but I don't know how to sum such differences in each group and assign the values to a new column say E ,

Pandas parsing csv error - expected 1 fields found 9

女生的网名这么多〃 提交于 2021-02-08 10:47:20
问题 I'm trying to parse from a .csv file: planets = pd.read_csv("planets.csv", sep=',') But I always end up with this error: ParserError: Error tokenizing data. C error: Expected 1 fields in line 13, saw 9 This is how the first few lines of my csv file look like: # This file was produced by the test # Tue Apr 3 06:03:27 2018 # # COLUMN pl_hostname: Host Name # COLUMN pl_discmethod: Discovery Method # COLUMN pl_pnum: Number of Planets in System # COLUMN pl_orbper: Orbital Period [days] # COLUMN pl

pandas sum the differences between two columns in each group

試著忘記壹切 提交于 2021-02-08 10:45:26
问题 I have a df looks like, A B C D 2017-10-01 2017-10-11 M 2017-10 2017-10-02 2017-10-03 M 2017-10 2017-11-01 2017-11-04 B 2017-11 2017-11-08 2017-11-09 B 2017-11 2018-01-01 2018-01-03 A 2018-01 the dtype of A and B are datetime64 , C and D are of strings ; I like to groupby C and D and get the differences between B and A , df.groupby(['C', 'D']).apply(lambda row: row['B'] - row['A']) but I don't know how to sum such differences in each group and assign the values to a new column say E ,

What is the difference between math.isnan ,numpy.isnan and pandas.isnull in python 3?

元气小坏坏 提交于 2021-02-08 10:34:22
问题 A NaN of type decimal.Decimal causes: math.isnan to return True numpy.isnan to throw a TypeError exception. pandas.isnull to return False What is the difference between math.isnan, numpy.isnan and pandas.isnull? 回答1: The only difference between math.isnan and numpy.isnan is that numpy.isnan can handle lists, arrays, tuples whereas math.isnan can ONLY handle single integers or floats. However , I suggest using math.isnan when you just want to check if a number is nan because numpy takes

python 3.4 encoding in windows 8.1

匆匆过客 提交于 2021-02-08 10:33:12
问题 I use the script mentioned in this question, to check the encoding: import sys, locale, os print(sys.stdout.encoding) print(sys.stdout.isatty()) print(locale.getpreferredencoding()) print(sys.getfilesystemencoding()) print(os.environ["PYTHONIOENCODING"]) print(chr(246), chr(9786), chr(9787)) and I obtain (python 3.4, windows 8.1): windows-1252 False cp1252 mbcs windows-1252 ö Traceback (most recent call last): File "C:/Users/.../UTF8-comprovacio.py", line 8, in <module> print(chr(246), chr

What is the difference between math.isnan ,numpy.isnan and pandas.isnull in python 3?

寵の児 提交于 2021-02-08 10:31:02
问题 A NaN of type decimal.Decimal causes: math.isnan to return True numpy.isnan to throw a TypeError exception. pandas.isnull to return False What is the difference between math.isnan, numpy.isnan and pandas.isnull? 回答1: The only difference between math.isnan and numpy.isnan is that numpy.isnan can handle lists, arrays, tuples whereas math.isnan can ONLY handle single integers or floats. However , I suggest using math.isnan when you just want to check if a number is nan because numpy takes