Questions tagged [data-conversion]

This tag refers to the process of converting the data type of one piece of information into another type.

1963 questions
2324
votes
32 answers

How to convert a string to an integer in JavaScript

How do I convert a string to an integer in JavaScript?
None
1004
votes
17 answers

Java string to date conversion

What is the best way to convert a String in the format 'January 2, 2010' to a Date in Java? Ultimately, I want to break out the month, the day, and the year as integers so that I can use Date date = new…
littleK
  • 19,521
  • 30
  • 128
  • 188
969
votes
23 answers

How can I convert a Unix timestamp to DateTime and vice versa?

There is this example code, but then it starts talking about millisecond / nanosecond problems. The same question is on MSDN, Seconds since the Unix epoch in C#. This is what I've got so far: public Double CreatedEpoch { get { DateTime epoch…
Mark Ingram
  • 71,849
  • 51
  • 176
  • 230
261
votes
8 answers

How do I convert this list of dictionaries to a csv file?

I have a list of dictionaries that looks something like this: toCSV = [{'name':'bob','age':25,'weight':200},{'name':'jim','age':31,'weight':180}] What should I do to convert this to a csv file that looks something like…
backus
  • 4,076
  • 5
  • 28
  • 30
153
votes
5 answers

Python convert tuple to string

I have a tuple of characters like such: ('a', 'b', 'c', 'd', 'g', 'x', 'r', 'e') How do I convert it to a string so that it is like: 'abcdgxre'
intel3
  • 1,561
  • 2
  • 9
  • 4
139
votes
0 answers

python pandas dataframe columns convert to dict key and value

I have a pandas data frame with multiple columns and I would like to construct a dict from two columns: one as the dict's keys and the other as the dict's values. How can I do that? Dataframe: area count co tp DE Lake 10 …
perigee
  • 9,438
  • 11
  • 31
  • 35
137
votes
3 answers

Why does ~True result in -2?

In Python console: ~True Gives me: -2 Why? Can someone explain this particular case to me in binary?
lukaszkups
  • 5,790
  • 9
  • 47
  • 85
121
votes
16 answers

Java lib or app to convert CSV to XML file?

Is there an existing application or library in Java which will allow me to convert a CSV data file to XML file? The XML tags would be provided through possibly the first row containing column headings.
A Salim
  • 1,325
  • 2
  • 11
  • 16
117
votes
6 answers

How to convert result table to JSON array in MySQL

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 [ { …
ronkot
  • 5,915
  • 4
  • 27
  • 41
97
votes
7 answers

Convert string with comma to integer

Is there any neat method to convert "1,112" to integer 1112, instead of 1? I've got one, but not neat: "1,112".split(',').join.to_i #=> 1112
mCY
  • 2,731
  • 7
  • 25
  • 43
76
votes
12 answers

Convert 4 bytes to int

I'm reading a binary file like this: InputStream in = new FileInputStream( file ); byte[] buffer = new byte[1024]; while( ( in.read(buffer ) > -1 ) { int a = // ??? } What I want to do it to read up to 4 bytes and create a int value from those…
OscarRyz
  • 196,001
  • 113
  • 385
  • 569
72
votes
12 answers

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

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…
Andrus
  • 26,339
  • 60
  • 204
  • 378
66
votes
26 answers

iOS convert large numbers to smaller format

How can I convert all numbers that are more than 3 digits down to a 4 digit or less number? This is exactly what I mean: 10345 = 10.3k 10012 = 10k 123546 = 123.5k 4384324 = 4.3m Rounding is not entirely important, but an added plus. I have looked…
Kyle Begeman
  • 7,169
  • 9
  • 40
  • 58
59
votes
5 answers

Converting SVG file to Android Vector Drawable XML while keeping the group structure in place

I want to convert SVG files to Android Vector Drawable XMLs. I need the structure of the SVG. To the extend that the SVG groups multiple elements together, I need that grouping to also be reflected in the Android Vector Drawable. Unfortunately, the…
Christian
  • 25,249
  • 40
  • 134
  • 225
48
votes
1 answer

Convert Pandas dataframe to Dask dataframe

Suppose I have pandas dataframe as: df=pd.DataFrame({'a':[1,2,3],'b':[4,5,6]}) When I convert it into dask dataframe what should name and divisions parameter consist of: from dask import dataframe as dd…
rey
  • 1,213
  • 3
  • 11
  • 14
1
2 3
99 100