data-conversion

python pandas dataframe columns convert to dict key and value

半腔热情 提交于 2019-11-28 16:04:14
From a Python pandas dataframe with multi-columns, I would like to construct a dict from only two columns. One as dict's keys and another as dict's values. How can I do that? Dataframe: area count co tp DE Lake 10 7 Forest 20 5 FR Lake 30 2 Forest 40 3 Need to define area as key, count as value in dict. Thank you in advance. If lakes is your DataFrame , you can do something like area_dict = dict(zip(lakes.area, lakes.count)) user2643517 With pandas it can be done as: If lakes is your DataFrame: area_dict = lakes.to_dict('records') You can also do this if you want to play around with pandas.

Data Conversion Issue in SSIS package - Text to GUID

旧时模样 提交于 2019-11-28 14:09:21
I am developing a SSIS package that will open an Excel spreadsheet and import the data into a database table in SQL Server 2008. When I try to convert the Excel column data type: Unicode String [DT_WSTR] to a unique identifier data type: unique identifier [DT_GUID] , I get the following error: "Invalid character value for cast specification" What do I need to do to resolve the conversion error? I used a Derived Column Transformation Editor and to wrap the excel column value in squrly brackets {} in order for the SSIS package to properly convert the Unicode String into a GUID. I want to mention

Why does Ruby's String#to_i sometimes return 0 when the string contains a number?

ぃ、小莉子 提交于 2019-11-28 13:19:29
I was just trying out Ruby and I came across String#to_i . Suppose I have this code: var1 = '6 sldasdhkjas' var2 = 'aljdfldjlfjldsfjl 6' Why does puts var1.to_i output 6 when puts var2.to_i gives 0 ? The to_i method returns the number that is formed by all parseable digits at the start of a string. Your first string starts with a with digit so to_i returns that, the second string doesn't start with a digit so 0 is returned. BTW, whitespace is ignored, so " 123abc".to_i returns 123. From the documentation for String#to_i : Returns the result of interpreting leading characters in str as an

DateTime Conversion and Parsing DateTime.Now.ToString(“MM/dd/yyyy hh:mm:ss.fff”)

余生长醉 提交于 2019-11-28 08:47:32
问题 I store some DateTime in a CSV log with: DateTime.Now.ToString("MM/dd/yyyy hh:mm:ss.fff") When I try to read it I found something like: "05/15/2012 10:09:28.650" The problem is when I try to cast it as a DateTime again... DateTime.Parse("05/15/2012 10:09:28.650"); Throws an Exception "Invalid DateTime" or something like that... How can I properly re-read the DateTime? 回答1: You can use DateTime.ParseExact: string format = "MM/dd/yyyy hh:mm:ss.fff"; DateTime d = DateTime.ParseExact("05/15/2012

Matching records based on Person Name

纵饮孤独 提交于 2019-11-28 04:35:00
Are there any tools or methods that can be used for matching by a person's name between two different data sources? The systems have no other common information and the names have been entered differently in many cases. Examples of non-exact matches: King Jr., Martin Luther = King, Martin (exclude suffix) Erving, Dr. J. = Erving, J. (exclude prefix) Obama, Barak Hussein = Obama, Barak (exclude middle name) Pufnstuf, H.R. = Pufnstuf, Haibane Renmei (match abbreviations) Tankengine, Thomas = Tankengine, Tom (match common nicknames) Flair, Rick "the Natureboy" = Flair, Natureboy (match on

Why am I getting a “[SQL0802] Data conversion of data mapping error” exception?

南楼画角 提交于 2019-11-28 01:54:49
I am not very familiar with iseries/DB2. However, I work on a website that uses it as its primary database. A new column was recently added to an existing table. When I view it via AS400, I see the following data type: Type: S Length: 9 Dec: 2 This tells me it's a numeric field with 6 digits before the decimal point, and 2 digits after the decimal point. When I query the data with a simple SELECT ( SELECT MYCOL FROM MYTABLE ), I get back all the records without a problem. However, when I try using a DISTINCT , GROUP BY , or ORDER BY on that same column I get the following exception: [SQL0802]

Convert char* to uint8_t

主宰稳场 提交于 2019-11-28 00:48:29
问题 I transfer message trough a CAN protocol . To do so, the CAN message needs data of uint8_t type . So I need to convert my char* to uint8_t. With my research on this site, I produce this code : char* bufferSlidePressure = ui->canDataModifiableTableWidget->item(6,3)->text().toUtf8().data();//My char* /* Conversion */ uint8_t slidePressure [8]; sscanf(bufferSlidePressure,"%c", &slidePressure[0]); As you may see, my char* must fit in sliderPressure[0] . My problem is that even if I have no error

Convert String with Dot or Comma as decimal separator to number in JavaScript

和自甴很熟 提交于 2019-11-27 21:47:28
An input element contains numbers a where comma or dot is used as decimal separator and space may be used to group thousands like this: '1,2' '110 000,23' '100 1.23' How would one convert them to a float number in the browser using JavaScript? jQuery and jQuery UI are used. Number(string) returns NaN and parseFloat() stops on first space or comma. hytest Do a replace first: parseFloat(str.replace(',','.').replace(' ','')) Shafiq The perfect solution accounting.js is a tiny JavaScript library for number, money and currency formatting. Check this for ref I realise I'm late to the party, but I

How to convert result table to JSON array in MySQL

假装没事ソ 提交于 2019-11-27 18:46:20
I'd like to convert result table to JSON array in MySQL using preferably only plain MySQL commands. For example with query SELECT name, phone FROM person; | name | phone | | Jack | 12345 | | John | 23455 | the expected JSON output would be [ { "name": "Jack", "phone": 12345 }, { "name": "John", "phone": 23455 } ] Is there way to do that in plain MySQL? EDIT: There are some answers how to do this with e.g. MySQL and PHP , but I couldn't find pure MySQL solution. New solution: Built using Your great comments, thanks! SELECT JSON_ARRAYAGG(JSON_OBJECT('name', name, 'phone', phone)) from Person;

Convert Latitude and Longitude to point in 3D space

 ̄綄美尐妖づ 提交于 2019-11-27 18:24:23
I need to convert latitude and longitude values to a point in the 3-dimensional space. I've been trying this for about 2 hours now, but I do not get the correct results. The Equirectangular coordinates come from openflights.org . I've tried several combinations of cos and sin , but the result did never look like our little beloved earth. In the following, you can see the result of applying the conversion Wikipedia suggests. I think one can guess from context what c4d.Vector is. def llarToWorld(latit, longit, altid, rad): x = math.sin(longit) * math.cos(latit) z = math.sin(longit) * math.sin